Q. Write a program to accept two integers x and n and compute x^n
Program
#include <stdio.h>
#include <math.h>
void main()
{
long int x,n,pow=1,j=1;
printf("Enter the values of X and n : ");
scanf("%d %d",&x,&n);
pow=x;
while(n!=j)
{
pow=pow*x;
j++;
}
printf(" %d to the power %d = %d",x,n,pow);
}
Output:
Enter the values of X and n : 4 5
4 to the power 5 = 1024
Program
#include <stdio.h>
#include <math.h>
void main()
{
long int x,n,pow=1,j=1;
printf("Enter the values of X and n : ");
scanf("%d %d",&x,&n);
pow=x;
while(n!=j)
{
pow=pow*x;
j++;
}
printf(" %d to the power %d = %d",x,n,pow);
}
Output:
Enter the values of X and n : 4 5
4 to the power 5 = 1024
0 Comments