Wap to find the nth term of the following series__ 1,2,2,4,4,4,4,8,8,8,8,8,8,8,8,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16......................................


#include<stdio.h>
#include<math.h>
void main()
{
    int a=1,b=1,c,n;
    printf("enter the no for which u want the term");
    scanf("%d",&n);
    while(a<n)
        a=a+pow(2,b++);
    c=pow(2,--b);
    if((c<=n)&&(n<=a))
        printf("\n%d",c);
}


NOTE-  i have compiled this program in codeblocks if u do it in turbo c++  use  conio.h  header file in the beginning  and getch()  a the  last.

No comments:

Post a Comment

Implemet Stack in python

  class Stack : def __init__ ( self , data ): self . stack = [] if ( data ): self . stack . append ( da...