palindrome string program 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.7
10
#include <stdio.h>
#include <string.h>
int main()
{
char str[80];
int length;
printf("\nEnter a string to check if it's a palindrome: ");
scanf("%s", str); // string input
length = strlen(str); // finding the string length
int i, j, count;
for (i = 0, j = length - 1, count = 0; i < length; i++, j--)
{
// matching string first character with the string last character
if (str[i] == str[j])
{
count++; // if character match, increasing count by one.
}
}
if (count == length) // if count == length, then the string is a palindrome.
{
printf("'%s' is a palindrome.\n", str);
}
else // otherwise the string is not a palindrome.
{
printf("'%s' is not a palindrome.\n", str);
}
return 0;
}
Thank you!
10
0
3.78
9
// 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!
9
0
3
1
#include <stdio.h>#include <string.h> int main(){ char text[100]; int begin, middle, end, length = 0; gets(text); while ( text[length] != '\0' ) length++; end = length - 1; middle = length/2; for( begin = 0 ; begin < middle ; begin++ ) { if ( text[begin] != text[end] ) { printf("Not a palindrome.\n"); break; } end--; } if( begin == middle ) printf("Palindrome.\n"); return 0;}
Thank you!
1
0
4.33
10
#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!
10
0
4
4
#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!
4
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 \
-
-
-
-
-
-
-