gpt4 book ai didi

c - 如何使用 for 循环找到 x 次幂 n 直到用户不想退出

转载 作者:行者123 更新时间:2023-11-30 17:46:53 28 4
gpt4 key购买 nike

我已经做到了这一点,但我不知道如何进一步进行

#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);
}

请你帮我写一个示例程序来显示 x 的 n 次幂,直到用户不想退出循环

最佳答案

只需要一点清理。

设置m=1
选择一个不同的变量来要求 -1。
printf() 移至 while 循环。
格式

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);
}
}
<小时/>

看起来OP已经消失了....

关于c - 如何使用 for 循环找到 x 次幂 n 直到用户不想退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19107933/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com