Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Mathematics ProgramRSS Feeds

Program to print values of 2 raise to power N, N and 2 raise to power -n

Posted By: Millie Brown     Category: C Programming     Views: 6859

Write a program to print values of 2 raise to power N, N and 2 raise to power -n.

Code for Program to print values of 2 raise to power N, N and 2 raise to power -n in C Programming

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

void main()
{
    longint p;
    int n;
    double q;

    printf("-------------------------------------------\n");
    printf(" 2 to power n       n       2 to power -n\n");
    printf("-------------------------------------------\n");
    p=1;

    for(n=0;n<21;n++)
    {
        if(n==0)
        {
            p=1;
        }
        else
        {
            p=p*2;
        }
        q=1.0/(double)p;
        printf("%10ld %10d %20.12lf\n",p,n,q);
    }
    printf("-------------------------------------------\n");
    getch();
}
  
Share: 



Millie Brown
Millie Brown author of Program to print values of 2 raise to power N, N and 2 raise to power -n is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
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!