You must Sign In to post a response.
  • Category: Programming

    Program to find whether given number is palindrome using C.


    Studying for C programming exam? Searching for solution to finding if a number is a palindrome or not? On this Ask Expert page you can check out responses from experts to your question and decide how to proceed with exam preparation.

    Question paper of Diploma in Computer Engineering (affiliated by MSBTE, Mumbai) for Summer 2018 contain the following question. This question carry 4 marks. It is expected that some explanation about the question is given. This question is asked in question paper of PIC(Programming in C) of I scheme with subject code 22226. So waiting for a solution to the asked question in C language only.
    Q) Develop a program to accept an integer number and print whether it is palindrome or not.
    [ 4 Marks]
  • Answers

    2 Answers found.
  • The thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
    This thread will be reviewed shortly.
    If you think this thread contain inappropriate content, please report to webmaster.
    Palindrome number is the number whose individual digits when separated and make cube of these individual digits. Afterwards when these cubes are added together and a number is formed and if this number is exactly equal with original number then we say that given number is palindrome number. 153 is a palindrome number. Let us check it's palindrome property.

    153
    =(1*1*1) + (5*5*5) +(3*3*3)
    =1+125+27
    =153
    So 153 is a palindrome number.

    Let us check it with number 152.

    152
    =(1*1*1)+(5*5*5)+(2*2*2)
    =1+125+8
    =134
    So 152 and resultant 134 are not equal numbers. Hence 152 is not a palindrome number.

    Following is the program to check whether given number is palindrome or not.
    Please include stdio.h and conio.h header files before declaration of main function.

    //PROGRAM TO CHECK WHETHER GIVEN NUMBER IS PALINDROME OR NOT.
    #include
    #include
    void main(void)
    {
    int num,s=0,r,m;
    clrscr();
    printf("Enter any integer number to check palindrome property\n");
    scanf("%d",&num);
    m=num;
    for(num=num;num>0;num=num/10)
    {
    r=num%10;
    s=s+(r*r*r);
    }
    if(s==m)
    {
    printf("\nNumber %d is a palindrome number",m);
    }
    else
    {
    printf("\nNumber %d is not a palindrome number",m);
    }
    getch();
    }
    While checking whether given number is palindrome or not, we have to separate all its individual digits. For this purpose we use statement r=num%10 inside the for loop. This statement divides the num by 10 and give remainder. So in first iteration r=3. Then num=num/10 statement appears and it also divides num by 10 and assign the quotient to num itself. So when num is 153 then after num=num/10, new num is 15. The above procedure goes on till num is greater than zero. Once num becomes less than zero the loop get terminated.
    Inside the loop we have added cube of separated individual digit with variable s whose initial value is zero.
    We have use variable m to hold initial value of num in the beginning because at the end of the loop value of num becomes zero. For taking decision whether given variable num is palindrome or not we use if statement with variables s and m with comparison operator.

  • The thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
    This thread will be reviewed shortly.
    If you think this thread contain inappropriate content, please report to webmaster.
    The reverse of a given number is equal to the same number. If you take n vlaue is a 121 just consider. If you reverse this number the value is a same 121. Such type of numbers are called palindrome numbers. Below is a program to check whether the number is palindrome or not in c programming :
    First include header file after #include between less than and greater than sign standard I/O and console I/O

    #include
    #include
    void main()
    {
    int a[10], num, i=0, result=0, n;
    Printf("Enter the number");
    Scanf("" %d", & n) ;
    num=n;
    while(num! =0)
    {
    result=result*10
    a[i]=num%10;
    num=num10;
    result=result+a[i];
    i++;
    }
    if(result==n)
    Printf("The number is palindrome");
    getch();
    }

    Output :
    Enter the number
    5225
    The number is palindrome


  • Sign In to post your comments