mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-25 06:49:36 +03:00
Merge pull request #2 from prateekiiest/master
Updating solution for Palindrome
This commit is contained in:
commit
1de05bd0b7
26
palindrome.c
Normal file
26
palindrome.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
int n, reversedInteger = 0, remainder, originalInteger;
|
||||
|
||||
printf("Enter an integer: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
originalInteger = n;
|
||||
|
||||
// reversed integer is stored in variable
|
||||
while( n!=0 )
|
||||
{
|
||||
remainder = n%10;
|
||||
reversedInteger = reversedInteger*10 + remainder;
|
||||
n /= 10;
|
||||
}
|
||||
|
||||
// palindrome if orignalInteger and reversedInteger are equal
|
||||
if (originalInteger == reversedInteger)
|
||||
printf("%d is a palindrome.", originalInteger);
|
||||
else
|
||||
printf("%d is not a palindrome.", originalInteger);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user