[英]how to find x power n using for loop till user don't want to exit
I have done upto this and i don't know how to proceed further 我已经做到了这一点,但我不知道如何进一步
#include<stdio.h>
int main()
{
int x,n,m,i;
printf("Enter the value of x: ");
scanf("%d",&x);
printf("\nEnter the value of n: ");
scanf("%d",&n);
for(i=0;i<n;i++)
m=m*x;
printf("x=%d;n=%d;m=%d",x,n,m);
while(m!=-1);
m=m*x;
i=i+1;
printf("enter the -1 to end");
scanf("%d",&m);
}
Will you please help me to write a sample program to show x power n till user don't want to exit the loop 您能帮我写一个示例程序来显示x的幂n直到用户不想退出循环吗
Just need a little clean-up. 只需要一点清理。
Set m=1
设置m=1
Choose a different variable to ask for -1. 选择一个不同的变量要求-1。
Move the printf()
to the while loop. 将printf()
移至while循环。
Format 格式
int main() {
int x, n, m, i;
printf("Enter the value of x: ");
scanf("%d", &x);
printf("\nEnter the value of n: ");
scanf("%d", &n);
m = 1;
for (i = 0; i < n; i++)
m = m * x;
while (n != -1) {
printf("x=%d;n=%d;m=%d\n", x, n, m);
m = m * x;
i = i + 1;
printf("enter the -1 to end ");
scanf("%d", &n);
}
}
Looks like OP went away .... 好像OP走了....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.