web123456

C language - Pastoral number

C language - Pastoral number

Number of palindromes:
Determine whether it is a palindrome number. That is, 12321 is the palindrome number.
Input: any number.
Output: If it is a palindrome number, it outputs "true", not a palindrome number and outputs "false".

example:
 Example Input12321
Example Output
true

1. Save arrays and compare them with arrays

#include<>
int main(){
	int i,j,input;
	int num[100];
	printf("Example Input\n");
	scanf("%d",&input);
	for(i=0;input>0;i++){
		num[i]=input%10;		//Put each bit into an array
		input=input/10;
	}
	for(j=0;j<i/2;j++){
		if(num[j]!=num[i-j-1]) break;	//Compare both sides
	}
	i/2==j?printf("Example Output\ntrue"):printf("Example Output\nfalse");
	return 0;
}

2. Calculate the countdown comparison

#include<>
int main(){
	int i,tmp,input,sum=0;
	printf("Example Input\n");
	scanf("%d",&input);
	for(i=input;i;i/=10){
		tmp=i%10;
		sum=sum*10+tmp;		// Calculate the reciprocal
	}
	sum==input?printf("Example Output\ntrue\n"):printf("Example Output\nfalse\n");
	return 0;
}