WAP to determine weather a given number is palindrome or not - C

Q. Write a program to determine whether a given number is palindrome or not, using function and demonstrating with argument and with return value.   
#BIT- 2018-Group A- Qno.1 b. 8 Marks - Solution, #BIT_FirstSem_2017_7N0_8 Marks_Solution #Assignment3bSolution
 ==>Code goes like this

#include<stdio.h>
int palindrome(int );
int main()
{
    int num,original,rev;
    printf("Enter a number:");
    scanf("%d",&num);
    original=num;
    rev=palindrome(num);   // calling function by passing values to function
    if (original==rev)    //Comparing original & reverse number
    printf("\n Palindrome Number");
    else
    printf("\n Not Palindrome");
    return 0;
}

int palindrome(int num)  //receiving number passed by main function
{
    int rev=0,rem;
    while(num!=0)      //reverse number checking starts
    {
    rem=num%10;
    rev=rev*10+rem;
    num=num/10;
    }                  //reverse number checking ends
    return rev;       // returning values to main function
}

Output:













Output1:










I have used Dev CPP to compile this program.
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment