In: Computer Science
Question
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.
and give me an output please
use printf and scanf
#include int main(void) { //Declare required variables
//read two integers x , n from the keyboard
//compute xn using for loop
printf("< Your name >\n"); printf("< Your ID >\n"); return 0; } |
C code:
#include <stdio.h>
int main(void)
{
//intializing variables
int x,n,total=1;
//accepting x and n
scanf("%d%d",&x,&n);
//looping for n times
for(int i=1;i<=n;i++)
//multiplying current value of total with x
total*=x;
//printing total
printf("%d\n",total);
//print Your name
printf("< Your name >\n");
//print Your ID
printf("< Your ID >\n");
return 0;
}
Screenshot:
Input and Output: