Sum of Series||C language||programming_info ||Series problem 8

Calculate the sum of series
2,6,12,20,30,...,n

Solution using C language:
#include <stdio.h>
int main() {
   int n;
   printf("Enter the range\n");
   scanf("%d",&n);
   int sum = ((n*(n+1))/2)+((n*(n+1)*(2*n+1))/6);
   printf("the sum of series till %d is %d", n,sum);
   return 0;
}

Output:
Enter the range
3
the sum of  series till 3 is 20
Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support