Write a program using a 1D array to evaluate the following expressions:
Total = ∑ (Xi)^2
where summation is from i=1 to 10.
#include <math.h>
#include <stdio.h>
int main(){
int s=0;int num[11];
num[1]=12;
num[2]=15;
num[3]=17;
num[4]=19;
num[5]=34;
num[6]=40;
num[7]=35;
num[8]=34;
num[9]=24;
num[10]=26;
for(int i=1;i<=10;++i){
s=s+pow(num[i],2);
printf("%d\n",s);
}
return 0;
}
Comments
Leave a comment