各位c语言高手来帮个忙

来源:百度知道 编辑:UC知道 时间:2024/05/10 23:05:34
用c语言二级函数方面的知识帮我编一下程序
列出0~10000之间的所有其各位上的数字之和等于10的数。编写一个判断各位上的数字之和等于10的函数,并在主函数中调用它。
请看清楚题目,是用函数方面的知识,要用到函数的调用,谢了

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<stdio.h>
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!");
}

#include<stdio.h>