Error : "not all code path return a value"
what's the problem in this program..the program is to find the given number is a palindrome or not
class Program
{
static void Main(string[] args)
{
int number;
number = Convert.ToInt32(Console.ReadLine());
int rev = rev1(number);
Console.WriteLine(rev);
if (rev == number)
Console.WriteLine("is a palandrome");
else
Console.WriteLine("not a palandrome");
Console.ReadLine();
}
private static int rev1(int number)
{
int sum = 0;
if(number==0)
{
int j = number % 10;
sum = sum * 10 + j;
int c = sum;
rev1(number / 10);
return sum;
}
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Aug 6, 2013, 11:38 AM
VulpesPosted Aug 6, 2013, 11:08 AM
However, if you change your rev1 method as follows then it should work fine. There's no need for recursive calls.
VulpesPosted Aug 6, 2013, 10:50 AM
Also the line int c = sum; appears to be redundant:
return sum;
}