Wednesday 29 January 2020

cpp program to show average of five integers using function .

Source Code: 

#include<iostream>
using namespace std;
void average ()
{
int a,b,c,d,e;
float avg;
avg=(a+b+c+d+e)/5;
cout<<avg<<endl;
}
void sum()
{
int v,w,x,y,z,add;
cout<<"Enter 5 integers: ";
cin>>v>>w>>x>>y>>z;
add=v+w+x+y+z;
cout<<"The sum is: "<<endl;
cout<<add<<endl;
}
int main()
{
sum();
average ();
return 0;
}


Program Output: 
Enter 5 integers: 1
2
3
4
5
The sum is: 
15
The average is: 
5

No comments:

Post a Comment