ProAnswers.org

write a c program for generating sum of series 1+2^1+2^2.........2^n

[b]#include[/b]

 

[b]int[/b] [b]main[/b](){

 

    [b]int[/b] n,i;

    [b]int[/b] 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 : ");

 

    [b]for[/b](i =1;i<=n;i++){

         [b]if[/b] (i != n)

             printf("%d^2 + ",i);

         [b]else[/b]

             printf("%d^2 = %d ",i,sum);

    }

 

    [b]return[/b] 0;

}