Q. Write a C program to display the given number series and calculate sum of that series.
1 2 4 7 11 16 22 . . . . . . . . .n
Ans.
/*program to display the given series and calculating sum*/
#include<stdio.h>
#include<conio.h>
int main()
{
int i,n;
int sum=0,ser=1;
printf("Enter total elements in the series:");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
printf(" %d",ser);
sum=sum+ser;
ser=ser+i;
}
printf("\nSum of series = %d",sum);
getch();
getch();
return 0;
}
Output:-
Enter number of elements in the series : 7
1 2 4 7 11 16 22
Sum of series = 63
Comments
Post a Comment