palindrome 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.5
2
bool isPlaindrome(string s)
{
int i=0;
int j=s.length()-1;
while(i<j)
{
if(s[i]==s[j])
{i++;
j--;}
else break;
}
if (i==j || i>j) return 1;
else return 0;
}
Thank you!
2
0
4.25
4
// 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!
4
0
4
8
#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!
8
0
4.33
3
#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!
3
0
3
1
#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!
1
0
Are there any code examples left?
New code examples in category Other
-
Other 2023-03-27 22:50:10 how to select the whole line in vscode with keyboard shortcut
-
Other 2022-03-27 22:45:24 income of a web developer
-
Other 2022-03-27 22:35:01 \pyrcc_main.py: File does not exist 'resources.qrc'
-
Other 2022-03-27 22:30:45 rick roll embed code
-
Other 2022-03-27 22:20:08 Circuit_04_Potentiometer
-
Other 2022-03-27 22:20:05 iterative power
-
Other 2022-03-27 22:15:11 flutter run all
-
Other 2022-03-27 22:10:05 when is karlson release
-
Other 2022-03-27 22:10:02 wp .htaccess example
-
Other 2022-03-27 22:00:08 bash pause in file read line by line