HOW TO DO C PROGRAMMING?

1. Write a program that prompts the user for 5 decimal (double) values and then

prints:

a. the sum

b. the product

c. the average

THIS IS FOR C PROGRAMMING

Update:

there was a minor problem in what you typed and i am trying to figure it out :(:( but for the most part, thank you so very much for the help Colt.

Comments

  • Here is another solution.

    My predecessor used the wrong format specifier for scanf and for printf.

    That is what compelled me to re-write his code.

    The code with the error compiled and produced output; you could show it to your teacher, who in return - in a better case scenario - would point out the errors. In case you were the one who would have produced that code, you probably would have found more than one person to point out errors and this could very well have been more teaching and better than just absorbing - unreflected in the worst case scenario - a given solution and sell it as your own ... :O)

    #include <stdio.h>

    // #include <stdlib.h>

    int main()

    {

    double num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0;

    printf("Please enter the 5 double numbers ");

    scanf("%lf %lf %lf %lf %lf",&num1, &num2, &num3, &num4, &num5);

    while(getchar() != '\n');

    printf("\n Sum: %.2lf"

    "\nProduct: %.2lf"

    "\nAverage: %.2lf\n", num1+num2+num3+num4+num5, num1*num2*num3*num4*num5, (num1+num2+num3+num4+num5)/5.0);

    // system("pause");

    return 0;

    }

  • include <stdio.h>

    main()

    {

    //declare variables

    double num1 = 0;

    double num2 = 0;

    double num3 = 0;

    double num4 = 0;

    double num5 = 0;

    int sum = 0;

    int product = 0;

    int average = 0;

    //prompt user

    printf("Please enter the 5 double numbers\n");

    scanf("%d",&num1);

    scanf("%d",&num2);

    scanf("%d",&num3);

    scanf("%d",&num4);

    scanf("%d",&num5);

    //calculations

    sum = (num1+num2+num3+num4+num5);

    product = (num1*num2*num3*num4*num5);

    average = sum / 5;

    //print results

    printf("\nSum is %d",sum);

    printf("\nProduct is %d",sum);

    printf("\nAverage is %d",sum);

    }

  • Okay... so... what's your question?

    Here's a simple tutorial for C

    http://www.academictutorials.com/c/

Sign In or Register to comment.