Write a C program that asks the user to enter two integers x and
n. Then the program computes
xn (=x * x * x …… (n times)) using for
loop.
using printf scanf
Please find below code and don't forget to give a Like.
Please refer below screenshot for code and output.
Explanation:
Taking total for total values and taking input in x and n.
Assign total to 1,
since for 1 time the x value will be x. So for i ==1, total will be equal to x.
Code:
#include <stdio.h>
int main()
{ int x,n,total=1;
printf("Enter x and n values:");
scanf("%d %d",&x,&n);
for(int i=1;i<=n;i++){
total=total*x;
}
printf("X power N values is:%d",total);
return 0;
}
Output:
Get Answers For Free
Most questions answered within 1 hours.