UVA10018 Reverse and Add

Source: Internet
Author: User

Problem Link: UVA10018 Reverse and Add. Basic Training questions, written in C language program.

Test instructions: Enter the number of test cases N, and then enter n positive integers, plus the integer in reverse order, if and not palindrome number , and the inverse of the integer and sum, until it becomes a palindrome integer, at least one addition, the last output addition number and palindrome number.

In the program, the function of calculating the inverse integer is encapsulated into the function reverse () and the main program logic becomes simple.

Use function encapsulation function, make the program function logical localization, the program is more concise and understandable.

The C language Program of AC is as follows:

/* UVA10018 Reverse and ADD */#include <stdio.h>unsigned int Reverse (unsigned int n) {    int rev = 0;    while (n) {        Rev = rev * + N;        n/=;    }    return rev;} int main (void) {    int n, count;    unsigned p, rev;    scanf ("%d", &n);    while (n--) {        scanf ("%d", &p);        Rev = reverse (p);        p + = rev;        Count = 1;        Rev = reverse (p);        while (P! = rev) {            p + = rev;            count++;            Rev = reverse (P);        }        printf ("%d%u\n", count, p);    }    return 0;}


UVA10018 Reverse and Add

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.