Answers for "palindrome in c using function"

C
2

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");
}
Posted by: Guest on June-24-2021
0

palindrome in c using function

#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;
}
Posted by: Guest on June-23-2021
-1

palindrome program in c

#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;
}
Posted by: Guest on September-23-2020

Code answers related to "palindrome in c using function"

Code answers related to "C"

Browse Popular Code Answers by Language