C Language: Judge whether a number of palindrome number (palindrome number is also a number, the character of the number is the positive and negative sequence is the same number, such as: 12321,3443) __c language

Source: Internet
Author: User
Tags assert

Palindrome number of the positive and negative sequence is the same number, so we put this number of high-low-level exchange, that is, 1234->4321, and then use the new number to compare with the previous digital exchange is equal, that is, can determine whether this number is a palindrome number. Note : Negative numbers are not palindrome numbers.

Judge whether a number of palindrome number (palindrome number is also a number, the number is characterized by positive and negative sequence is the same number, such as: 12321,3443)
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

int if_palindrome_num (int n)
{
	assert (n > 0);
	int num = n;
	int res = 0;
	Do
	{
		res = res * + num%;
		num = NUM/10;
	} while (num);
	if (res = = N)
	{return
		1;

	}
	return 0;
}

int main ()
{
	int n = 12321;
	int temp = 0;
	temp = If_palindrome_num (n);
	if (temp = 0)
	{
		printf ("The%d is not palindrome number.\n", n);
	}
	else
	{
		printf ("The%d is palindrome number.\n", n);
	}
	System ("pause");
	return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.