Tuesday, 5 September 2017

Write a program to generate the series 18 20 44 138 560 2810 16872 ...



 #include<stdio.h>

 int main()
 {
 // (18*i)+(2*i)
 int a=18,i,n;
 scanf("%d",&n);
  printf("%d ",a);
 for(i=1;i<n;i++)
 {
 a=(a*i)+(2*i);
 printf("%d ",a);
 }
 return(0);
 }

Sample Input :
7

Sample Output :
18 20 44 138 560 2810 16872

No comments:

Post a Comment