问题遇到的现象和发生背景
求整数的各位数字之和
编译器vs2022
(scanf没有错误)
想写个自定义函数实现求和
用代码块功能插入代码,请勿粘贴截图
#include<stdio.h>
int shuzihe(int y);
int main()
{
int n;
scanf_s("%d", &n);
printf("%d", shuzihe(n));
return 0;
}
int shuzihe(int y)
{
int result;
if (y == 0)
result = 0;
else if (y % 10 != 0)
result = shuzihe(y);
return result;
}