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

To find out the sum of series 

1^3 + 2^3 + …. + n^3



Solution using C language:
  1. #include<stdio.h>
  2. #include<math.h>
  3. int main() {
  4. int n,i;
  5. int sum=0;
  6. printf("Enter the n i.e. max values of series: ");
  7. scanf("%d",&n);
  8. sum = pow(((n * (n + 1) ) / 2),2);
  9. printf("Sum of the series : ");
  10. for (i =1;i<=n;i++) {
  11. if (i != n)
  12. printf("%d^3 + ",i); else
  13. printf("%d^3 = %d ",i,sum);
  14. }
  15. return 0;
  16. }

Output:
Enter the n i.e. max values of series: 3
Sum of the series: 1^3 + 2^3 + 3^3 = 36
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