Kod:
include <stdio.h>
#include <string.h>
int ispalindromic(unsigned long number); //returns 1 if number is palindromic
int main()
{
unsigned long counter;//for loop
unsigned long limit;//the limit entered by user.
int control;//to control if the entered value is valid
int y=1;//to control if the screen is full
printf("Please Enter the Limit \
as an integer value between 1 and 4294967295 : ");
control=scanf("%ld",&limit);
getchar();
// if no using getchar function program doesn't show numbers between
// 1 and 100 because I use getchar function to wait the enter key
// in order users to see the numbers until screen is full
while ((control==0) || (control==-1))
//if invalid value entered then give error message and scan for a new valid value
{
printf("\
An invalid value was entered.\n");
getchar();
printf("Please Enter the Limit \
as an integer value between 1 and 4294967295 : \n");
control=scanf("%ld",&limit);
}
printf("Palindromic numbers between 1 and %ld :\
\n",limit);
for (counter=1;counter<=limit;++counter)
{
if (ispalindromic(counter))
{
if (y>24)//if screen is full wait for user's reading
{
printf("Press <enter> to contiue\n");
getchar();//wait until user's pressing enter
y=1;
}
printf("%ld\
\n",counter);//if palindromic write to screen
++y;
}
}
printf("\
All palindromic numbers were shown between 1 and %ld...\
\n",limit);
printf("Press <enter> to exit\
\n");
getchar();//Wait for user's pressing enter
return 0;
}
int ispalindromic(unsigned long number) //returns 1 if number is palindromic
{
int temp;//later it will be return value of function
char snumber[11]=""; //for converting to string
int counter;
int lenght;
sprintf(snumber,"%ld",number); //converts integer to string (number==>snumber)
lenght=strlen(snumber);
temp=1;
for (counter=0;counter<lenght/2;++counter)
{
if ((int)snumber[counter]==(int)snumber[lenght-counter-1]) temp=1;
else
{
temp=0;
return temp;
}
}
return temp;
}