为啥输入后没反应?

Bill_Kwok 2020-01-14 02:16:44
# include <stdio.h>
# include <math.h>
float fac(int n){
float t =1.;
int i;
for(i=2;i<=n;i++) t*=i;
return t;
}
float cp(int n,int m){
float x;
x = fac(n)/(fac(m)*fac(n-m));
return x;
}
int main(){
int n,m;
float s;
do{
printf("Please enter two numbers n and m:\n");
scanf("%d%d\n",&n,&m);
} while (n<m);
s = cp(n,m);
printf("%n!/(%m!(%n-%m)!)=%d",n,m,n,m,s);
return 0;
}
...全文
54 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_1457346882 2020-01-14
  • 打赏
  • 举报
回复
scanf中只放你的输入数据类型(%d%lf等)和格式就好了,不要换行
输出格式printf中前面是原封不动要显示的字符加你要替换的变量的数据类型,同样是%d%f这种,然后后面逗号接要替换的变量,一个数据类型对应后面的一个变量,从左往右依次。他会自己去把你后面的变量的值放到你前面的对应位置输出,不要%变量名,这是错的
寻开心 2020-01-14
  • 打赏
  • 举报
回复
int main(){
int n,m;
float s;
do {
printf("Please enter two numbers n and m:\n");
scanf("%d%d",&n,&m); // 这里删除了 是“%d”后面的\n
} while (n<m);
s = cp(n,m);
printf("%d!/(%d!(%d-%d)!)=%d",n,m,n,m,s);
return 0;
}
Italink 2020-01-14
  • 打赏
  • 举报
回复
把你scanf中的\n去掉
Bill_Kwok 2020-01-14
  • 打赏
  • 举报
回复


输入4 和1 后,后面的程序似乎没有运行了。。。

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧