Create a class: “Palindrome” with private data members: upper_limit (int), lower_limit (int) and parameterized constructor, which initializes the values of both data members. Apart from initialization, this constructor also displays the count of palindrome numbers from upper_limit to lower_limit. [Example: upper_limit:50, lower_limit:10, count of palindrome numbers is: 4(11 , 22, 33 and 44), also make sure the value of upper_limit should be greater than lower_limit].
#include<stdio.h>
int main(){
int num, rem, reverse_num, temp, start, end;
printf("Enter the lower limit: ");
scanf("%d",&start);
printf("Enter the upper limit: ");
scanf("%d",&end);
printf("Palindrome numbers between %d and %d are: ",start,end);
for(num=start;num<=end;num++){
temp=num;
reverse_num=0;
while(temp){
rem=temp%10;
temp=temp/10;
reverse_num=reverse_num*10+rem;
}
if(num==reverse_num)
printf("%d ",num);
}
return 0;
}
Comments
Leave a comment