Week 7 Task 1-calculate the positive difference between two numbers

Source: Internet
Author: User
/** Copyright (c) 2012, School of Computer Science, Yantai University * All Rights Reserved. * Author: Zhao guanzhe * Completion Date: July 15, October 8, 2012 * version number: V1.0 ** input Description: two positive integers * Problem description: Given two positive integers, calculate the positive difference between two numbers and output *ProgramOutput: Given the positive difference between two numbers * Problem Analysis: by comparing the two numbers, we can ensure that the value is reduced by the limit and the positive difference is obtained *AlgorithmDESIGN: omitted */# include <iostream> using namespace STD; int main () {int A, B, C, D, E; cout <"enter, value of B: "; CIN> A> B; If (A> B) {c = A; D = B;} else {c = B; D = A;} e = c-d; cout <"positive difference =" <e <"\ n"; return 0 ;}

 

Running result:

Experience:

After a while of thinking, he handed over the task to complete. After independent thinking and continuous debugging, no errors were displayed. This program can also be simpler and simpler. It is being modified .............

Knowledge Point summary;

When calculating the positive difference value, compare the size by programming, and reduce the value by a small margin. The result is an integer. Do not subtract the two numbers directly to avoid negative values.

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.