标题:大佬们 这个程序问题出在哪? 它会直接退出循环
只看楼主
Niderhoger
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2019-11-3
结帖率:100%
 问题点数:0 回复次数:2 
大佬们 这个程序问题出在哪? 它会直接退出循环
//power.c--计算数的整数幂
#include <stdio.h>
double power(double n, int p);
int main(void)
{
    double x, xpow;
    int exp;

    printf("Enter a number and the positive integer power");
    printf(" to which\nthe number will be raised.Enter q");
    printf(" to quit.\n");
   
    while (scanf_s("lf %d", &x, &exp) == 2)
    {
        xpow = power(x, exp);
        printf("%.3g to the power %d is %.5g\n", x, exp, xpow);
        printf("Enter next pair of numbers or q to quit,\n");
    }
    printf("Hope you enjoyed this power trip -- bye!\b");

    return 0;
}

double power(double n, int p)
{
    double pow = 1.0;
    int i;

    for (i = 1; i <= p; i++)
        pow *= n;
    return pow;
}
搜索更多相关主题的帖子: int power printf exp double 
2019-11-03 16:29
纯蓝之刃
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:76
帖 子:554
专家分:3690
注 册:2019-7-29
得分:0 
while (scanf_s("lf %d", &x, &exp) == 2)

少了一个%。while (scanf_s("%lf %d", &x, &exp) == 2)

一沙一世界,一花一天堂。无限掌中置,刹那成永恒。
2019-11-03 19:27
Niderhoger
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2019-11-3
得分:0 
回复 2楼 纯蓝之刃
绝了..我竟然没发现  谢了
2019-11-03 20:54



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-497594-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017654 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved