[英]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
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);
}
您的 function 被聲明為 int,這意味着它應該返回一個 int。 您的 function 不返回 int - 事實上,它不返回任何內容。
正如@Retired Ninja 所說,您需要弄清楚您希望 function 返回什么,並添加適當的 return 語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.