bool funtion(int n){
int gewei = 0,shiwei=0,baiwei=0,qianwei=0;
int result = 0;
//计算各个位上的数值[因为在c语言中,整数整
//数的结果依旧是整数。]
gewei = n%10;
shiwei = (n/10)%10;
baiwei = (n/100)%10;
qianwei= (n/1000)%10;
result = gewei+shiwei+baiwei+qianwei;
if(result = 10){return ture;}
else{return false;}
}
#include
int whether(int m);
void main()
{int m;
for(m=10;m<=9999;m++)
if(whether(m)==1) printf("%5d",m);
getch();
}
int whether(int m)
{ int a,b,c,d;
if(m>=10&&m<=99)
{a=m/10; b=m%10;
if(a+b==10) return 1;
else ruturn 0;}
else if(m>=100&&m<=999)
{a=m/100;b=(m/10)%10;c=m%10;
if(a+b+c=10) ruturn 1;
else ruturn 0;}
else if(m>=1000<=9999)
{a=m/1000;b=(m/100)%10;c=(m%100)/10;d=m%10;
if(a+b+c+d==10) return 1;
else ruturn 0;}
}
上机调试已成功!!! 两位的却是高手,但是不适合初学者。
#include
main()
{
int gewei = 0,shiwei=0,baiwei=0,qianwei=0;
int result = 0; int n;
printf("please input the number n:");
scanf("%d",&n);
gewei = n%10;
shiwei = (n/10)%10;
baiwei = (n/100)%10;
qianwei= (n/1000)%10;
result = gewei+shiwei+baiwei+qianwei;
if(result = 10)
printf("the result is %d\n");
else
printf("the number is not your want!");
}
写的不赖