Question
using c for this code
IV Code Fragment Write the statements necessary to code this formula. Using temporary variables and breaking up the computation is highly advised. Write the declaration for any additional variables you use. Assume the variable n is an integer. You do not have to do any error checking. Assume n is a valid value. You have been hired to write code that will check the following formula for the sum of the first n positive integers squared. The sum of the first n positive integers squared is given by: Sum = n(n+1)(2n + 1)/6 Thus the SUM of the first 4 positive Integers squared is : The formula (with n = 4) gives Your code will compute this sum both ways and print whether or not they match. Print Formula is correct if the sums match and formula is wrong if they do not
Explanation / Answer
it give only sum of the squres
--------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,sum=0;
clrscr();
printf("Enter Value of N (terms) : ");
scanf("%d",&n);
printf(" ");
for(i=1;i<=n;i++)
{
printf("%4d",i*i);
sum+=i*i;
}
printf(" Sum of Square Natural Number upto %d terms = %d ",n,sum);
getch();
}
it gives squares and their sum.