Problem no 5:Sum of Digit is Pallindrome or not

QUESTION:

Given a number N.Find if the digit sum(or sum of digits) of N is a Palindrome number or not.
Note:A Palindrome number is a number which stays the same when reversed.Example- 121,131,7 etc.

Example 1:

Input:
N=56
Output:
1
Explanation:
The digit sum of 56 is 5+6=11.
Since, 11 is a palindrome number.Thus,
answer is 1.

Example 2:

Input:
N=98
Output:
0
Explanation:
The digit sum of 98 is 9+8=17.
Since 17 is not a palindrome,thus, answer
is 0.

 ANSWER:

int isDigitSumPalindrome(int N) {
int sum=0;
          while(N>0)
          {
              int rem=N%10;
              sum=sum+rem;
              N=N/10;
          }
          int number=sum;
          int newnumber=0;
          while(sum>0)
          {
              int rem=sum%10;
              newnumber=newnumber*10+rem;
              sum=sum/10;
             
          }
          if(newnumber==number)
          {
              return 1;
          }
          else
          {
              return 0;
          }
    }

Comments

Popular posts from this blog

problem 3: given two integers N and M. The problem is to find the number closest to N and divisible by M. If there are more than one such number, then output the one having maximum absolute value.

problem no 7:Given two numbers A and B, find Kth digit from right of AB.

Problem no 16: count the number of squares below N.