Search This Blog

Tuesday 23 November 2021

4. Write a C Program to read a number, find the sum of the digits, reverse the number and check it for palindrome.

/*4. Write a C Program to read a number, find the sum of the digits, reverse the number and check it for palindrome */

#include<stdio.h>

void main()

{

     int num,temp,digit,sum=0,rev=0;

     clrscr();

     printf("Enter a number:");

     scanf("%d",&num);

     temp=num;

     while(num>0)

     {

          digit=num%10;

          num=num/10;

          sum=sum+digit;

          rev=rev*10+digit;

     }

     printf("\nSum of Digits=%d",sum);

     printf("\nReverse Number=%d",rev);

     if(rev==temp)

     {

          printf("\n%d is Palindrome.",temp);

     }

     else

          printf("\n%d is Not a Palindrome.",temp);

     getch();

}

No comments :

Post a Comment

FREE Hit Counters