programming-examples/c/Series_Programs/Write a c program to find out the sum of series 12 + 22 + n2.c
2019-11-15 12:59:38 +01:00

15 lines
406 B
C

#include<stdio.h>
int main() {
int n,i;
int sum=0;
printf("Enter the n i.e. max values of series: ");
scanf("%d",&n);
sum = (n * (n + 1) * (2 * n + 1 )) / 6;
printf("Sum of the series : ");
for (i =1;i<=n;i++) {
if (i != n)
printf("%d^2 + ",i); else
printf("%d^2 = %d ",i,sum);
}
return 0;
}