将三个数按从大到小输出。
- #include <stdio.h>
- int main()
- {
- int arr[3];
- int a, b, c;
- for(a = 0; a < 3; a++)
- {
- scanf_s("%d", &arr[a]);
- }
- for(b = 0; b < 3; b++)
- {
- for(a = 0; a < 3 - b; a+
- arr[a+ 1] = c;
- }
- }
- }
- for(a = 0; a < 3; a++)+)
- {
- if(arr[a] < arr[a + 1])
- {
- c= arr[a];
- arr[a]= arr[a + 1];
- {
- printf("%d ",arr[a]);
- }
- system("pause");
- return 0;
- }
另一种程序:
- #include <stdio.h>
- int main()
- {
- int a, b, c;
- scanf_s("%d", &a);
- scanf_s("%d", &b);
- scanf_s("%d", &c);
- if (a > b)
- {
- if (a > c)
- {
- if (b > c)
- {
- printf("%d,%d,%d", a, b, c);
- }
- else
- {
- printf("%d,%d,%d", a, c, b);
- }
- }
- else
- {
- printf("%d,%d,%d", c, a, b);
- }
- }
- else
- {
- if (a > c)
- {
- printf("%d,%d,%d", b, a, c);
- }
- else
- {
- if (b > c)
- {
- printf("%d,%d,%d", b, c, a);
- }
- else
- {
- printf("%d,%d,%d", c, b, a);
- }
- }
- }
- system("pause");
- return 0;
- }
修正后的程序:
- #include <stdio.h>
- void Swap(int* px, int* py)
- {
- int tmp = *px;
- *px = *py;
- *py = tmp;
- }
- int main()
- {
- int a=2,b=14,c=3;
- if(a<b)
- {
- Swap(&a, &b);
- }
- if(a<c)
- {
- Swap(&a, &c);
- }
- if(b<c)
- {
- Swap(&b, &c);
- }
- printf("%d %d %d\n", a,b,c);
- system("pause");
- return 0;
- }