ppupil2

PRF192 ws3.q3

Mar 1st, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <conio.h>
  5.  
  6. int reverse(int a); /* find the reverse of a */
  7. int main() {
  8.     int m,n,a;
  9.     char ch, chr;
  10.    
  11.     /* input & check validation*/
  12.     while (1) {
  13.         printf("Enter m, n: ");
  14.         fflush(stdin);
  15.         scanf("%d%c%d%c", &m, &ch, &n, &chr);
  16.         if (ch == ' ' && chr == '\n' && m<n) {
  17.             break;
  18.         }
  19.         else {
  20.             printf("Invalid input!\n");
  21.         }
  22.     }
  23.    
  24.     /* find palindrome numbers */
  25.     printf("Palindrome numbers are:");
  26.     for (int i = m; i<=n; i++) {
  27.        if(i == reverse(i)) {
  28.         printf(" %d,", i);
  29.        }
  30.     }
  31.    
  32.     return(0); 
  33. }
  34.  
  35. /* function find the reverse of a */
  36. int reverse(int a){
  37.     int c,x,rv;
  38.     x=1; rv=0;
  39.     while (a>0) {
  40.         c=a%10;
  41.         rv= rv*10 +c;
  42.         a/=10;
  43.     }
  44.     return (rv);
  45. }
Add Comment
Please, Sign In to add comment