write a program to display the sum of digits of every palindrome number from m to n.input of m to n should be given by user.
Answers
Answer:
#include <stdio.h>
int reverse(int n){
int rev = 0;
while(n!=0){
int r = n%10;
rev = rev*10+r;
n/=10;
}
return rev;
}
int palindrome(int n){
if(n >= 0 && n <= 9){
return 0;
}
else if(reverse(n) == n){
return 1;
}
return 0;
}
int sum(int n){
int sum = 0;
while(n!=0){
int r = n%10;
sum = sum + r;
n/=10;
}
return sum;
}
int main() {
int start , end;
printf("Enter the starting number of the range:");
scanf("%d" , &start);
printf("Enter the ending number of the range:");
scanf("%d" , &end);
for(int i = start; i < end; i++){
if(palindrome(i) == 1){
printf("%d is a palindrome and the sum of digits of %d is %d \n" , i , i , sum(i));
}
}
printf("%d" , palindrome(121));
return 0;
}
Explanation: