Blogger templates

Pages

Tuesday 29 May 2012

Write a C++ Program to Compute the Sum and Average of Two Numbers

Sum of Two Numbers

Manipulators:
  • Manipulators are the Operators that are used to Format the Data Display.
  • Example: endl
  • It is included in the <iomanip> Header File.
Statement of C++ Program: Enter Two Numbers and Calculate the Sum and Average of Two Numbers:

#include<iostream.h>
#include<iomanip.h>                  

int main()
{
float n1, n2 ;
float Sum, Average ;

Cout<< " Enter the Value of Two Numbers" << "endl";        
Cin>> n1;
Cin>> n2;
Sum = n1+ n2;
Average = Sum / 2 ;

Cout<< " Sum= " << Sum << "\n" ;
Cout<< " Average= " << Average << "\n" ;
return(0);                                                               // It is also Written as  return 0;
}                                                 // End of main()

Output:
 Enter the Value of Two Numbers
 5  10
 Sum= 15
 Average= 7.5

0 comments:

Post a Comment