C++ Program by using pointer that receives array of 5 integers numbers and calculate the sum, average and standard deviation of these numbers.
C++ Program Calculate the Sum, Average and standard Deviation of these Numbers.
Object: Write a C++ program by using pointer that receives array of 5 integers from keyboard and calculate the sum, average and standard deviation of these numbers. C++ projects for beginners with source code
Code:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
void main()
{
int num[5],i,sum=0,avg,stdvi,var=0;
int *p[5];
cout<<“Enter 5 Numbbers:\n”;
for(i=0;i<5;i++)
{
cin>>num[i];
p[i]=&num[i];
sum+=*p[i];
}
avg=sum/5;
for(i=0;i<5;i++)
{
var+=pow(num[i]-avg,2);
var=var/5;
stdvi=sqrt(var);
}
cout<<“Sum of 5 Numbers is: “<<sum;
cout<<“\nAverage of 5 Numbers is: “<<avg;
cout<<“\nStandard deviation of these Numbers is: “<<stdvi;
getch();
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include<iostream> #include<conio.h> #include<math.h> using namespace std; void main() { int num[5],i,sum=0,avg,stdvi,var=0; int *p[5]; cout<<"Enter 5 Numbbers:\n"; for(i=0;i<5;i++) { cin>>num[i]; p[i]=&num[i]; sum+=*p[i]; } avg=sum/5; for(i=0;i<5;i++) { var+=pow(num[i]-avg,2); var=var/5; stdvi=sqrt(var); } cout<<"Sum of 5 Numbers is: "<<sum; cout<<"\nAverage of 5 Numbers is: "<<avg; cout<<"\nStandard deviation of these Numbers is: "<<stdvi; getch(); } |
1 Response
[…] C++ Program by using pointer that receives array of 5 integers numbers and calculate the sum, averag… […]