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

Pebble merchant, to design a car that travels along the room and gives the ...

to design a car that travels along the room and gives the length of the room

Write a simple telephone book program, Write a simple telephone book progra...

Write a simple telephone book program that stores the names and phone numbers of your friends/acquaintances in a file. Your program should have the abilities to: a. Add entries (n

Areaundercurve, Write a program to find the area under the curve y = f(x) b...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve betw .

Luminous jewel - a polishing game, Byteland county is very famous for lumin...

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Create a c project, The project will include Arena models (only .doe files)...

The project will include Arena models (only .doe files) and MSWord document for the report. Thereport must contain the following sections: 1. Introduction: (a)    Statemen

Prepare an ipad application clash of clans like game, Prepare an iPad appli...

Prepare an iPad application Clash of Clans like game I would like to prepare a free city building app with the in app purchase possibility. An example game could be Clash of Cla

Determine the size of an interger data type without using , Determine the s...

Determine the size of an interger data type without using sizeof() function? A: #include int main() { int *i ; int *j = i + 1; cout }

Advantages to the use of functions, Question: (a) What is a function? A...

Question: (a) What is a function? Are functions needed when writing a C program? (b) State one of the advantages to the use of functions. (c) What do you meant by underst

Area under curve, Write a program to find the area under the curve y = f(x)...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b.

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