Thursday, July 18, 2019

Generate series 1 1 2 3 4 9 27 16 81 243 and find nth term

#include <stdio.h>
#include<math.h>
int main()
{
int i,j,t,u,s,n,c=0;

scanf("%d",&n);

u=n;
for(i=0;i<n;i++)
{
   
        s=pow(2,i);
        if(c==u)
        {
      printf(" %d",s);
      break;
        }
    c++;
    t=pow(3,i);
     if(c==u)
    {
      printf(" %d",t);
      break;
    }

   
    c++;
  
      
   
}

    return 0;
}

No comments:

Post a Comment