Thursday, 6 February 2014

Write a program in C to find the value of x^n where x and n are positive integers

#include <stdio.h>
main()
{
    int x,n,result=1,i=1;
    printf("\nEnter the value of x=");
    scanf("%d",&x);
    printf("\nEnter the value of n=");
    scanf("%d",&n);
    while(i<=n)
    {
        result=result*x;
        i++;
    }
    printf("\n %d^%d=%d",x,n,result);
}

No comments:

Post a Comment