Monday, July 18, 2011

Write a c program to find out the sum of series 1 + 2 + �. + n.




Sum
of 1 + 2 + �. + n series in c programming language




#include

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;



printf("Sum of
the series: ");



for(i =1;i <=
n;i++){

if (i!=n)

printf("%d +
",i);

else

printf("%d =

No comments:

Post a Comment