+ 1

What’s wrong?

#include<stdio.h> reversef(int); int main() { int num,reversenum; printf("\nEnter any number:"); scanf("%d",&num); reversenum=reversef(num); printf("\nAfter reverse the no is :%d",reversenum); return 0; } int sum=0,rem; reversef(int num){ if(num){ rem=num%10; sum=sum*10+rem; reversef(num/10); } else return sum; return sum; } What is wrong with this code it says error : reversef : Undeclared identifier.

13th Dec 2019, 7:31 PM
Saba
3 Antworten
+ 1
You defined the function after you called it. 1.Define function void func(){} 2. Use function int main() { func(); return 0; }
13th Dec 2019, 8:15 PM
Manual
Manual - avatar
+ 1
The code requires a type declaration for the return value of the reversef() function. You only need to add int just before declaring and defining the reversef function as seen below: //Function Declaration int reversef(int) and //Function Definition int reversef(int num) { ... } See the code with inline comments. https://code.sololearn.com/cjjU8E1wsa6A/
13th Dec 2019, 8:40 PM
David Carroll
David Carroll - avatar
0
Corrected all the errors, -------------------------------------------------------------- #include<stdio.h> int reversef(int); int sum=0,rem; int main() { int num,reversenum; printf("\nEnter any number:"); scanf("%d",&num); reversenum=reversef(num); printf("\nAfter reverse the no is :%d",reversenum); return 0; } int reversef(int num) { if(num) { rem=num%10; sum=sum*10+rem; reversef(num/10); } else return sum; } --------------------------------------------------------------
13th Dec 2019, 9:06 PM
Dewesh Chopra
Dewesh Chopra - avatar