Sunday 15 March 2015

Program to find the value of x^n using C

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

void main()
{
int x, n, count = 1, sum = 1 ;
clrscr() ;
printf("Enter the value of x : ") ;
scanf("%d", &x) ;
printf("\nEnter the value of n : ") ;
scanf("%d", &n) ;
while(count <= n)
{
sum = sum * x ;
count ++ ;
}
printf("\nThe power of %d^%d is : %d", x, n, sum) ;
getch() ;
}

RUN 1 :
~~~~~~~
Enter the value of x : 2
Enter the value of n : 4
The power of 2^4 is : 16

No comments:

Post a Comment