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

Arrays, how to declare arrays

how to declare arrays

Sentence, Consider text comprised of sentences and sentences comprised of w...

Consider text comprised of sentences and sentences comprised of words. Words in a sentence will be space delimited. Given a text and K strings, task is to find out the number valid

Identifier and constant, What are  Id e n t i f ie rs a n d C o...

What are  Id e n t i f ie rs a n d C o n s t a n ts in C++? Id e n t i f ie r a n d C o n s t a n t : I d e n t i f ie r

I need poker room auto seat program, Project Description: I want a scrip...

Project Description: I want a script for an online poker site. It needs to be scanning all the required tables and when the table meets certain criteria it should take a seat at

Super ASCII String Cost, A string S is said to be "Super ASCII", if it cont...

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

Salary of an employe, basic salary of an employe.the allowence are House r...

basic salary of an employe.the allowence are House rent 20% of basic salary Medical allowence is 10% of basic salary conveyence allowence is 10% calculate anrd display gross salar

Car rental system, complex coding with structure and file handling

complex coding with structure and file handling

Saha, find the minimum total number of shelves

find the minimum total number of shelves

Explain processing a data file, Explain Processing A Data File? Mainly ...

Explain Processing A Data File? Mainly data file applications needs that a data file be altered as it is being processed. For instance in an application involving the processin

Inside and outside type casting, depth description of the inside and outsid...

depth description of the inside and outside typecasting

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