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

Write a c program to add two complex numbers, #include stdio.h   struct  c...

#include stdio.h   struct  complex   {   float real;   float imag;   };   struct complex complexadd(struct complex,struct  complex);   void main()     {          Date: 26

Probabilistic hough transform, Two kinds of line detection are implemented ...

Two kinds of line detection are implemented in OpenCV, the Hough Transform and the probabilistic Hough transform. Assume that there are n feature points in an image and that it tak

What operators can or cannot be overloaded?, A: Mostly can be overloaded. T...

A: Mostly can be overloaded. The only C operators which can't be are. and?: (and sizeof, that is technically an operator). C++ adds a few of its own operators, mostly which can be

Minimum shelf, #questionAt a shop of marbles, packs of marbles are prepared...

#questionAt a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets

What happens if you write following code?, What happens if you write follow...

What happens if you write following code? string& foo()

Assignment, write a c program chat illustrates the creation of child proces...

write a c program chat illustrates the creation of child process using fork system call. One process finds sum of even series and other process finds sum of odd series.

Create a program of several prototypes for functions, In this assignment th...

In this assignment the main has been written for you in the file phone_book_main.cpp. You will also notice that a class called Person has been declared as having several prototypes

C , why c is middle level language?

why c is middle level language?

Explain structured programming, Explain structured programming The prin...

Explain structured programming The principal idea behind structured programming was as easy as the idea of "divide and conquer." A computer program could be regarded as having

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