| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1142 人关注过本帖
标题:大佬们 这个程序问题出在哪? 它会直接退出循环
只看楼主 加入收藏
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
帖 子:566
专家分: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
快速回复:大佬们 这个程序问题出在哪? 它会直接退出循环
数据加载中...
 
   



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

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