Get Answers to all your Questions

header-bg qa

Write a C program to find sum of series 1^2 +2^2 +3^2...+n^2 for given n

Answers (1)

best_answer

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

Posted by

Deependra Verma

View full answer