Q:

C program to find sum of the square of all natural numbers from 1 to N

0

 C program to find sum of the square of all natural numbers from 1 to N.
Series: 1^2+2^2+3^2+4^2+..N^2

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

/*This program will print the sum of the square 
of all natural numbers from 1 to N.*/

#include<stdio.h>
    
int main()
{
	int i,N;
	unsigned long sum;
	
	/*read value of N*/
	printf("Enter the value of N: ");
	scanf("%d",&N);
	
	/*set sum by 0*/
	sum=0;
	
	/*calculate sum of the series*/
	for(i=1;i<=N;i++)
		sum= sum+ (i*i);
	
	/*print the sum*/
	
	printf("Sum of the series is: %ld\n",sum);
	
	return 0;
}
    Enter the value of N: 100
    Sum of the series is: 338350

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to find the sum of Natural Number/Facto... >>
<< C program to find sum of all natural numbers...