pc011.c (1287B)
1 /* Write a C program that takes two positive integers, L (Lower Bound) 2 and U (Upper Bound), as input from the user. The program must find and print 3 the count of all numbers between L and U (inclusive) that 4 are also a Palindrome Number. */ 5 6 #include <stdio.h> 7 #define true 1 8 #define false 0 9 10 int isPalindrome(int num) 11 { 12 int temp = num, numRev = 0; 13 while (temp > 0) 14 { 15 numRev = (numRev * 10) + (temp % 10); 16 temp /= 10; 17 } 18 if (num == numRev) 19 return true; 20 else 21 return false; 22 } 23 24 int main() 25 { 26 int uBound, lBound, num, palindromeCount = 0; 27 printf("Enter the Lower Bound and Upper Bound : "); 28 if (scanf("%d %d", &lBound, &uBound) != 2) 29 { 30 printf("\nOnly Integer values are allowed."); 31 return 1; 32 } 33 if (lBound < 0 || uBound < 0 || lBound > uBound) 34 { 35 printf("\nPlease enter appropriate inforamtion."); 36 return 1; 37 } 38 printf("Palindrome Numbers from %d to %d :", lBound, uBound); 39 for (num = lBound; num <= uBound; num++) 40 { 41 if (isPalindrome(num)) 42 { 43 printf(" %d", num); 44 palindromeCount++; 45 } 46 } 47 printf("\nTotal Palindrome number found inside the range (%d to %d) : %d", lBound, uBound, palindromeCount); 48 return 0; 49 }