Write a program using single subscripted variable to evoluate the following expressions:
total=x1^2 + x2^2 +.......................+x10^2 .
This problem is very easy to implement & solve.
just make an array & take input.
C program :
total=x1^2 + x2^2 +.......................+x10^2 .
This problem is very easy to implement & solve.
just make an array & take input.
total=0 // initialise total to 0 initially
i=0; //you can use for loop instead of using while
while(i<10)
{
total=total+(arr[i]*arr[i]); // this is main operation
i++;
}
C program :
/*
Write a program using single subscripted variable to evoluate the following expressions:
total=x1^2 + x2^2 +.......................+x10^2
*/
#include<stdio.h>
main()
{
float arr[10];
float total=0;
int i;
/*......................taking input................*/
for(i=0;i<10;i++)
{
printf("\n enter %dth element :",i+1);
scanf("%f",&arr[i]);
}//end of for loop & input operation
/*............operation................................*/
i=0;
while(i<10)
{
total=total+(arr[i]*arr[i]);
i++;
}//end of operation & while loop
printf("Requre sum of squre is : %.2f",total); //%2f use for limit no of digit after decimal
}
OUTPUT :
sum of square |
No comments:
Post a Comment
THANKS FOR UR GREAT COMMENT