Write down a program to calculate the sum of following series: 1+2+3+4+——+n


binaryweblearning


Write down a program to calculate the sum of following series: 1+2+3+4+——+n

include<stdio.h>
int main()
{
int i,n,sum=0;
printf(“Enter the value of n: \n”);
scanf(“%d”, &n);
for(i=1; i<=n; i++)
{
sum=sum+i;
}
printf(“Total sum is %d”, sum);
return 0;
}

Post a Comment

0 Comments