Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Program to display series 2,4,16,256... using while loop

Posted By: Guilherme Silva     Category: C Programming     Views: 4998

Write a program to display series 2,4,16,256... using while loop.

Code for Program to display series 2,4,16,256... using while loop in C Programming

#include<stdio.h>
#include<conio.h>

int main()
{
    int n,x;  // declare the variable longdouble i=2;  //declare the variable of long double type
    clrscr();  

    printf("Enter the number : ");
    scanf("%d",&n);

    printf("\n");

    x=1;
    while(x<=n)   //  loop will be execute till the value of x I less or equal n
    {
        printf("%.2Lf\n",i);  // print the value of I upto 2 decimals only
        x++;
        i*=i;
    }

    getch();

    return 0;
}


Output:

Enter the number : 4

2.00
4.00
16.00
256.00
  
Share: 


Didn't find what you were looking for? Find more on Program to display series 2,4,16,256... using while loop Or get search suggestion and latest updates.

Guilherme  Silva
Guilherme Silva author of Program to display series 2,4,16,256... using while loop is from Salvador, Brazil.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!