本文介绍了节目找到数字之和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法在此找出问题:
#包括LT&;&stdio.h中GT;
诠释的main()
{
诠释A,B,计数;
计数= 0;
的printf(为输入值);
scanf函数(%d个,&安培; A);
而(一个大于0)
{
B = A%10;
数= B +计数;
A = A / 10; 的printf(由此简化的结果是%D,计数);
}
返回0;
}
解决方案
有href=\"http://www.codinghorror.com/blog/archives/001310.html\" rel=\"nofollow\">无声杀手一个在code:
scanf函数(%d个,&安培; A);
在scanf函数的多余空间将进入困难数字:这将匹配 12 lt;空>
,而不是 12
。替换%D
与%D
。
I can't figure out the problem in this:
#include<stdio.h>
int main()
{
int a,b,count ;
count =0;
printf("enter the value for a ");
scanf("%d ",&a);
while(a>0)
{
b=a%10;
count=b+count;
a=a/10;
printf ("hence the simplified result is %d",count);
}
return 0;
}
There's a silent killer in your code:
scanf("%d ",&a);
The extra space in your scanf will make entering numbers harder: this will match 12<space>
, but not 12
. Replace the "%d "
with "%d"
.
这篇关于节目找到数字之和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!