check is number is palindrome in C
#include <stdio.h>
#include <conio.h>
void main()
{
int n,i,r=0;
printf("Enter a number: ");
scanf("%d",&n);
for(i=n;i!=0;i)
{
r=r*10;
r=r+ i%10;
i=i/10;
}
if(r==n)
printf("palindrome");
else
printf("Not palindrome");
}
3
1
#include <stdio.h>
int main() {
int n, reversedN = 0, remainder, originalN;
printf("Enter an integer: ");
scanf("%d", &n);
originalN = n;
// reversed integer is stored in reversedN
while (n != 0) {
remainder = n % 10;
reversedN = reversedN * 10 + remainder;
n /= 10;
}
// palindrome if orignalN and reversedN are equal
if (originalN == reversedN)
printf("%d is a palindrome.", originalN);
else
printf("%d is not a palindrome.", originalN);
return 0;
}
Thank you!
1
0
0
0
#include <stdio.h>
#include <conio.h>
int palindrome (int num);
void main()
{
int n, ret;
printf("Enter the number: ");
scanf("%d",&n);
ret = palindrome(n);
if (ret == n)
printf("\nPalindrome\n");
else
printf("\nNot Palindrome\n");
}
int palindrome(int num)
{
int rem, rev=0;
while (num!=0)
{
rem = num % 10;
rev = rev * 10 + rem;
num /= 10;
}
return rev;
}
Thank you!
0
0
4.1
10
// this is for string
#include <stdio.h>
#include <string.h>
void main()
{
char a[100], b[100];
printf("Enter a string to check if it's a palindrome: ");
gets(a);
strcpy(b, a);
if (strcmp(a, b) == 0)
printf("\nThe string is palindrome.\n");
else
printf("\nThe string is not palindrome.\n");
getch();
}
Thank you!
10
0
Are there any code examples left?
New code examples in category C
-
C 2022-03-27 22:30:45 Problem Statement Print the following output: \ Input Format IN Output Format \
-
C 2022-03-27 18:30:08 how to free memory in c
-
C 2022-03-27 18:00:14 linux command line windows
-
C 2022-03-27 18:00:02 C example of if else
-
C 2022-03-27 17:10:18 sum of digits in c using for loop
-
C 2022-03-27 12:35:50 replace word in c
-
C 2022-03-27 07:40:11 How to setup a line length marker in vim
-
C 2022-03-27 07:35:09 Multi Select with icons htm;