[英]control reaches end of non-void function. How to solve this?
solution.c: In function 'subtractProductAndSum' Line 31: Char 1: error: control reaches end of non-void function [-Werror=return-type] [solution.c] } ^ cc1: some warnings being treated as errors solution.c: In function 'subtractProductAndSum' Line 31: Char 1: error: control reaches end of non-void function [-Werror=return-type] [solution.c] } ^ cc1: some warnings being treated as errors
int subtractProductAndSum(int n){
int k , j=n , count=0 , add=0 , multiply=1;
while(j>0){
j=j/10;
count++;
}
int p=count;
int arr[p];
while(n>0){
k=n%10;
n=n/10;
if(p>0){
arr[p-1]=k;
p--;
}
}
for(int i = 0; i <count ;i++){
add=add+arr[i];
multiply=multiply*arr[i];
}
int t=multiply-add;
printf("%d", t);
}
Your function is declared as an int, meaning it's expected to return an int.您的 function 被声明为 int,这意味着它应该返回一个 int。 Your function doesn't return an int -- in fact, it doesn't return anything.您的 function 不返回 int - 事实上,它不返回任何内容。
As @Retired Ninja said, you need to figure out what you want your function to return, and add an appropriate return statement.正如@Retired Ninja 所说,您需要弄清楚您希望 function 返回什么,并添加适当的 return 语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.