Compute the average of five numbers, C/C++ Programming

Assignment Help:

Step 1 Define the program headers and the variables 
 
  #include
  #include
  #include
  #include
void main()
  {
 
    char prompt;
    float a,b,c,d,e;
    float average,total;
 
Step 2 Request the numbers from the user by input
 
    printf("Enter in five numbers \n\r");
    scanf("%f",&a);
    scanf("%f",&b);
    scanf("%f",&c);
    scanf("%f",&d);
    scanf("%f",&e);
  
Step 3 Calculate the Sum of A,B,C,D,E
 
    total=a+b+c+d+e;
 
Step 4 Compute the average
 
    average= total/5;
 
Step 5 Display the results and Stop the program
  
    printf(" The average is %f \n\r",average); 
    printf("Press any key to exit \n\r");
    scanf("\n%c",&prompt);
 
    }

The total program is as follows
 
  #include
  #include
  #include
  #include
void main()
  {
    char prompt;  
    float a,b,c,d,e;
    float average,total;
    printf("Enter in five numbers \n\r");
    scanf("%f",&a);
    scanf("%f",&b);
    scanf("%f",&c);
    scanf("%f",&d);
    scanf("%f",&e);
    total=a+b+c+d+e;
    average= total/5.0;
    printf(" The average is %f \n\r",average); 
    printf("Press any key to exit \n\r");
    scanf("\n%c",&prompt);
 
  }
 
We could replace the following two lines 
 
    total=a+b+c+d+e;
    average= total/5.0;
with 
    average =(a+b+c+d+e)/5.0;
 
Hence the program becomes 
  #include
  #include
  #include
  #include
void main()
  {
    char prompt;
    float a,b,c,d,e;
    float average;
    printf("Enter in five numbers \n\r");
    scanf("%f",&a);
    scanf("%f",&b);
    scanf("%f",&c);
    scanf("%f",&d);
    scanf("%f",&e);
    average =(a+b+c+d+e)/5.0;
    printf(" The average is %f \n\r",average);   
    printf("Press any key to exit \n\r");
    scanf("\n%c",&prompt);
}


Related Discussions:- Compute the average of five numbers

Decodethecode, 6999066263304447777077766622337778 -----> message sent by th...

6999066263304447777077766622337778 -----> message sent by the first smuggler. my name is robert---------> message decoded by the second smuggler. Where ‘0’ denotes the "space". Ex

Explain control flow, Control Flow The control flow statements are used...

Control Flow The control flow statements are used when it is needed that the flow of the program is to be changed after taking some decision. This control flow statement theref

Encryption/Decryption, I need to include files so you can understand easier...

I need to include files so you can understand easier.

Described inline function?, A: The inline keyword tells the compiler to sub...

A: The inline keyword tells the compiler to substitute the code in the function de_nition for each instance of a function call. Though, substitution takes place only at the compile

Minimum shelves, write a c++ program, that finds the minimum total number o...

write a c++ program, that finds the minimum total number of shelves, including the initial one, required for this loading process.

Do i have to check for null after p = new fred()?, A: No. (Excluding if you...

A: No. (Excluding if you have an old compiler, you might have to force the new operator to throw an exception if it runs out of memory.) This turns out to be a real pain to alwa

Array, Write a program to count the prime number in array

Write a program to count the prime number in array

A program that divides the screen into n vertical bars, Write a function th...

Write a function that takes in a number n and divides the screen into n vertical bars, alternating black and white. (What should you do if someone puts in n=0 or n=-99?)

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd