c program to find the n'th power of a number

Description


This program prints the n'th power of a number. The value of the number and the power is read into the variables x and n. The value of r is initially set to 1. The program repeatedly multiplies r and x n times, using while loop. The result of this multiplication gives the n'th power of the given number.

Program


#include<stdio.h>

#include<conio.h>

void main()

{

int x,n,i=1,r=1;

clrscr();

printf("Enter the x & n value");

scanf("%d%d",&x,&n);

while(i<=n)

{

r=r*x;

i++;

}

printf("Value is %d",r);

getch();

}

No comments: