C language learning notes frist --- enter two numbers to compare the size, language learning frist ---

Source: Internet
Author: User

C language learning notes frist --- enter two numbers to compare the size, language learning frist ---

C # in the course of study, I asked how difficult it is. Since I learned this year, I am the first function to learn: I have input two numbers to compare the size and only perform exercises;

# Include "stdafx. h "# include <stdio. h> // contains stdio. h header file int max (int, int); // function declaration int main () {int a, B; // declare two integer variables printf ("input two integer :"); // use spaces to separate scanf ("% d", & a, & B); // assign the two integers to, B printf ("the max integer is % d. \ n ", max (a, B); // output the maximum value in integer form. a and B are the actual parameters (real parameters) return 0 ;} // Function Definition int max (int num1, int num2) {// num1, num2 is a formal parameter (parameter) if (num1> num2) {// If num1 is greater than num2 return num1; // return num1 and end max function} else {// If num2 is greater than num1 return num2; // return num2 and end max function }}

  

 


Input 10 numbers in C language and output them by size

This is the sort by the bubble method.
Main ()
{
Int I, j, temp;
Int a [10];
For (I = 0; I <10; I ++)
Scanf ("% d,", & a [I]); // you can enter 10 numbers here.
For (j = 0; j <= 9; j ++) // 10 peripheral Loops
{For (I = 0; I <10-j; I ++) // The number of cycles in the inner loop 10 minus the number of cycles in the periphery
If (a [I]> a [I + 1]) // compare whether a [I] is greater than a [I + 1]
{Temp = a [I]; // Let's just switch between a [I] And a [I + 1] so that a large number will follow the cycle.
A [I] = a [I + 1]; // This is the end
A [I + 1] = temp ;}
}
For (I = 1; I <11; I ++)
Printf ("% 5d,", a [I]); // outputs the result
Printf ("\ n ");
}

How to compile a C language program to compare the size of two numbers?

# Define Max (a, B) a> B? A: B

Related Article

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.