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