再想想……
[ 本帖最后由 有容就大 于 2012-2-29 22:28 编辑 ]
[ 本帖最后由 有容就大 于 2012-2-29 22:28 编辑 ]
梅尚程荀
马谭杨奚
#include <stdio.h> #define N 10 int main(void) { int max, min, i, j, index, a[N]; printf("Please input 10 number:\n"); for (i = 0; i < N; i++) { scanf("%d", &a[i]); } max = min = a[0]; for (i = 0; i < N; i++) { if (min > a[i]) min = a[i]; } for (j = 0; j < N; j++) { for (i = 0; i < N; i++) if (max < a[i]) { max = a[i]; index = i; } a[index] = min - 1; printf("a[%d] = %d\n", index, max); max = min - 1; } return 0; }
#include <stdio.h> #define N 10 int main(void) { int i, j, index, temp, a[N], b[N]; printf("Please input 10 number:\n"); for (i = 0; i < N; i++) { scanf("%d", &a[i]); } for (i = 0; i < N; i++) { b[i] = a[i]; } for (i = 0; i < N-1; i++) { index = i; for (j = i+1; j < N; j++) { if ( b[j] > b[index]) index = j; } if (index != i) { temp = b[i]; b[i] = b[index]; b[index] = temp; } } for (j = 0; j < N; j++) { for (i = 0; i < N; i++) { if (b[j] == a[i]) printf("a[%d] = %d\n", i, b[j]); } } return 0; }
#include <stdio.h> #define N 10 struct num_id { int data; int index; }a[N]; int main(void) { int i, j, index; struct num_id temp; printf("Please input 10 number:\n"); for (i = 0; i < N; i++) { scanf("%d", &a[i].data); a[i].index = i; } for (i = 0; i < N-1; i++) { index = i; for (j = i+1; j < N; j++) { if ( a[j].data > a[index].data) index = j; } if (index != i) { temp = a[i]; a[i] = a[index]; a[index] = temp; } } for (i = 0; i < N; i++) printf("a[%d] = %d\n", a[i].index, a[i].data); return 0; }