Thursday, March 3, 2016

Array element's square sum in C

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>
#include<math.h>

main() 
{
 int i,n;
 printf("Enter how long will be your array:\n");
 scanf("%d",&n);
 float x[n],value,total;
 total = 0.0;
 printf("Enter %d real number:\n",n);
 for(i=0; i<n; i++){
  scanf("%f",&value);
  x[i]=value;
  total = total + pow(x[i],2);
  printf("x[%d] = %.2f\n",i+1,x[i]);
 }
 
 printf("Total = %.2f\n",total);
 
}

No comments:

Post a Comment

Thank you for commenting. Please wait for response :)