i am trying to make a function to return true if the number is palindrome and return false if the number is not , so first i created a function that reverse the number then another function to tell if the reversed number is equal to the original number , but it not returning for me the correct output , any help ?
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
//Reversing a number
int DigitsReversing(int num)
{
int resultofR = 0;
while (num > 0)
{
resultofR = resultofR * 10 + num % 10;
num = num / 10;
}
return resultofR;
}
//telling if the original number equal to the reversed number if yes return if not return false
int isPali(int num)
{
DigitsReversing(num);
int resultofR;
if (num == resultofR)
return true;
else
return false;
return 0;
}
//calling the function
int main()
{
int num;
scanf("%d", &num);
printf("%d", isPali(num));
return 0;
}
edited **** :
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
int DigitsReversing(int num)
{
int resultofR = 0;
while (num > 0)
{
resultofR = resultofR * 10 + num % 10;
num = num / 10;
}
return resultofR;
}
bool isPali(int num , int resultofR)
{
resultofR = DigitsReversing(num);
if (num == resultofR)
return true;
else
return false;
}
int main()
{
int num, resultofR;
scanf("%d", &num);
resultofR = DigitsReversing(num);
isPali(num, resultofR);