7. write a C program to find the sum of individual digits of a positive integer and test given number is palindrome or not.


Program to find the sum of individual digits of a positive integer and test given number is palindrome or not.

Source Code:

#include <stdio.h>
int main()
{
 int n,sum=0,x,r,temp;
 printf("enter a number\n");
 scanf("%d",&n);
 while(n>0)
 {
  x=n%10;
  sum=sum+x;
  n=n/10;
 }
 printf("sum is=%d",sum);
 printf("enter the number\n");
 scanf("%d",&n);
 temp=n;
 while(n>0)
 {
     r=n%10;
     sum=(sum*10)+r;
     n=n/10;
 }
 if(temp==sum)
 {
     printf("palindrome number");
 }
 else
 {
 printf("not a palindrome number");
 }
 return 0;
 }

OutPut:

enter a number
15
sum is=6
enter the number
182
not a palindrome number

No comments:

Post a Comment