+ 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.
3 Answers
+ 1
You defined the function after you called it.
1.Define function
void func(){}
2. Use function
int main()
{
func();
return 0;
}
+ 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/
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;
}
--------------------------------------------------------------