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();
}
#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(); }
Pingback: C++ projects for beginners with source code - Codeboks
Valuable information. Lucky me I found your website by accident, and I’m shocked why this accident didn’t happened earlier! I bookmarked it.