Tuesday 5 September 2017

Write a program to generate the series 5 9 18 34 59 95 144 ....



 #include<stdio.h>
 #include<math.h>

 int main()
 {
 int n,i,a,d,e=5;
 scanf("%d",&n);
 printf("%d ",e);
 for(i=2;i<=n;i++)
 {
 d=pow(i,2);
 a=e+d;
 printf("%d ",a);
 e=a;
 }
 return(0);
 }

Sample Input :
7

Sample Output :
5 9 18 34 59 95 144

No comments:

Post a Comment