Write a program using a 1D array to evaluate the following expressions: Total = ∑ (Xi) 2 where summation is from i=1 to 10.
#include <stdio.h>
int main(void){
int arr [10] = {5,6,78,8,4,3,2,45,89,98};
//The expression is Total = summation(Xi) 2
int sum = 0.0;
for(int i =0; i<10; i++ ){
sum += arr[i];
}
int total = 2 * sum;
printf("The summation of elements in the array is: %d", total);
}
Comments
Leave a comment