1. Given the values of two integer variables, swap the contents of the two values.
int i = 1, j = 2, temp = 0; temp = i; i = j; j = temp; printf("i:%d j:%d", i, j);
2. It is not allowed to create temporary variables and exchange the contents of two numbers
int i = 1, j = 2; i = i + j; j = i - j; i = i - j; printf("i:%d j:%d", i, j);
3. Print the maximum value of 10 integers
int num[10] = {6,10,2,4,6,1,8,9,3,5}; int j, max = num[0], len = sizeof(num) / sizeof(num[0]); for (j = 1; j < len; j++) { if (num[j] > max) max = num[j]; } printf("The maximum number of these ten integers is: %d\n", max);4. Output the three numbers in descending order.
int a, b, c, temp; printf("Enter three numbers:\n"); scanf_s("%d %d %d", &a, &b, &c); if (a < b) { temp = a; a = b; b = temp; } if (b < c) { temp = b; b = c; c = temp; } if (a < b) { temp = a; a = b, b = temp; } printf("From big to small: %d %d %d\n", a, b, c);
5. Find the greatest common divisor of two numbers
int x, y, temp; printf("Please enter two numbers\n"); scanf_s("%d,%d", &x, &y); if (x < y) { temp = x; x = y; y = temp; } for (temp = y; x % temp || y % temp; temp --); printf("The greatest common divisor is: %d\n", temp);