Computer Science, asked by rakeshpotnuru, 7 months ago

Write a C 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

Answered by samarthkrv
1

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(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 sum of digits of it is %d \n" , i , sum(i));

           }

       }

   return 0;

}

Explanation:

Similar questions