intmain(){ int a, b, c, d, t; scanf("%d %d %d %d", &a, &b, &c, &d); if ( a > b ) { t = a; a = b; b = t; } if ( a > c ) { t = a; a = c; c = t; } if ( a > d ) { t = a; a = d; d = t; } if ( b > c ) { t = b; b = c; c = t; } if ( b > d ) { t = b; b = d; d = t; } if ( c > d ) { t = c; c = d; d = t; } printf("%d %d %d %d", a, b, c, d); return0; }
intmain(){ int n, i, s = 0, x, y = 1; scanf("%d", &n); for (i = 1; i <= n; i++) { y = 1; for (x = 1; x <= i; x++) { y *= x; } s += y; } printf("%d", s); return0; }
intmain(){ int i, a, b, c, y; for (i = 100 ; i <= 999; i++) { y = 0; a = i / 100; b = i / 10 % 10; c = i % 10; y = a * a * a + b * b * b + c * c * c; if (i == y) { printf("%d ", i); } } return0; }
zy4-2
题目
编程一程序,功能是:输出如下图形。其中,行数n由键盘输入。例如: 输入:5 输出: A BAB CBABC DCBABCD EDCBABCDE
intmain(){ int n, count, s; scanf("%d", &n); char a = 64, b; for (count = 1; count <= n; count++) { for (s = 1; s <= n - count; s++) { printf(" "); } for (a = 64, b = a + count; s <= n; b--, s++) { putchar(b); } for (a = 65; s >= n && s <= n + count - 1 ; s++) { a++; putchar(a); } printf("\n"); } return0; }
intmain(){ int x, n, h = 0; int a[N] = {0}; float s; scanf("%d", &n); for (x = 0; x < n; x++) { scanf("%d", &a[x]); h = h + a[x]; } s = h * 1.0 / n; printf("%.1f", s); return0; }
intmain(){ int n, i, j, p, q, sum, a[N]; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n; i++) { p = i; q = a[i]; for (j = i + 1; j < n; j++) { if (q > a[j]) { p = j; q = a[j]; } } if (i != p) { sum = a[i]; a[i] = a[p]; a[p] = sum; } printf("%d ", a[i]); } return0; }
intmain(){ int n, i, j; char s[N][50], *p; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%s", s[i]); } for (i = 0; i < n - 1; i++) { for (j = 0; j < n - i - 1; j++) { if (strcmp(s[j], s[j + 1]) > 0) { strcpy(p, s[j]); strcpy(s[j], s[j + 1]); strcpy(s[j + 1], p); } } } for (i = 0; i < n; i++) { printf("%s ", s[i]); } return0; }
intsort(int x[], int n){ int i, s = 0, p, q, j; for (i = 0; i < n; i++) { scanf("%d", &x[i]); } for (i = 0; i < n; i++) { p = i; q = x[i]; for (j = i + 1; j < n; j++) { if (q > x[j]) { p = j; q = x[j]; } } if (i != p) { s = x[i]; x[i] = x[p]; x[p] = s; } printf("%d ", x[i]); } }
intmain(){ int n, x[N]; scanf("%d", &n); sort(x, n); return0; }
编写一个从小到大排序(选择法)函数void sort(char (*p)[10],int n),其中n为整数个数。在main函数中输入n并输入n个国家英文名称,调用排序函数后输出。例如: 输入:5 China France Britain Russia America 输出:America Britain China France Russia
voidsort(char (*p)[10], int n){ int i, j; char *t; char u[10]; t = u; for (i = 0; i < n - 1; i++) { for (j = 0; j < n - i - 1; j++) { if (strcmp(p[j], p[j + 1]) > 0) { strcpy(t, p[j]); strcpy(p[j], p[j + 1]); strcpy(p[j + 1], t); } } } for (i = 0; i < n; i++) { printf("%s ", p[i]); } }
intmain(){ int n; char (*p)[10]; scanf("%d", &n); char x[50][10]; int i, j; for (i = 0; i < n; i++) { scanf("%s", x[i]); } for (i = 0; i < n; i++) { p = x; } sort(p, n); return0; }
voidmove(int a[], int n, int m){ int p, i; p = n - m; for (i = 0; p < n; i++, p++) { x[i] = a[p]; } for (p = 0; i < n; i++, p++) { x[i] = a[p]; } }
intmain(){ int a[1000]; int m, n, i; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } scanf("%d", &m); move(a, n, m); for (i = 0; i < n; i++) { printf("%d ", x[i]); } return0; }
zy10-2
题目
试编写一个摆花函数void flower(char f[][N],int n),函数的功能描述:同学们弄来了不多于26种花,每种花有多盆。为使有限的鲜花摆放得更美观,同学们决定把花摆成正方形图案,现在告诉你正方形的边长N(每盆花的直径为一个单位长,1<=N<=99,N为奇数),请你编程输出花所排成正方形图案(用大写字母代表花)。我们把图案的中心称为第1圈,中心向外依次是第2圈、第3圈……。中心是字母A,第2圈是字母B,第3圈是字母C,……,第26圈是字母Z,第27圈又是字母A,第28圈又是字母B,……Z,A,B……。在main函数中,输入n,调用flower函数后,输出图案,提醒:输出时每个字母前有一个空格。 例如 输入:15 则输出以下图案(输出时每个字母前留一个空格): H H H H H H H H H H H H H H H H G G G G G G G G G G G G G H H G F F F F F F F F F F F G H H G F E E E E E E E E E F G H H G F E D D D D D D D E F G H H G F E D C C C C C D E F G H H G F E D C B B B C D E F G H H G F E D C B A B C D E F G H H G F E D C B B B C D E F G H H G F E D C C C C C D E F G H H G F E D D D D D D D E F G H H G F E E E E E E E E E F G H H G F F F F F F F F F F F G H H G G G G G G G G G G G G G H H H H H H H H H H H H H H H H
voidflower(char f[][N], int n){ int k = 1; int i, j, t, b, c, d; t = (n + 1) / 2; b = t; c = n; d = n; while (k <= t) { for (i = k - 1; i <= n - k; i++) { for (j = k - 1; j <= n - k; j++) { d = n - 2 * (k - 1); if (d >= 52) { for (; d > 52;) { d = d % 52; } t = (d + 1) / 2; if ( k == 0) { f[i][j] = 65 + t - k; } else { f[i][j] = 65 + t - 1; } } else { f[i][j] = 65 + t - k; } } } k++; t = b; } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (j < n - 1) printf("%c ", f[i][j]); else printf("%c", f[i][j]); } printf("\n"); } }
BOOK *CreateLink(){ BOOK *h, *p, *r; int i; h = (BOOK *)malloc(sizeof(BOOK)); h -> next = NULL; r = h; for (i = 0; i < n; i++) { p = (BOOK *)malloc(sizeof(BOOK)); scanf("%s", p -> num); scanf("%s", p -> name); scanf("%f", &(p -> value)); r -> next = p; p -> next = NULL; r = p; getchar(); } return h; }
voidPrintLink( BOOK *h ){ BOOK *p = h -> next; for (; p != NULL;) { printf("%s %s %.2f\n", p -> num, p -> name, p -> value); p = p -> next; } }
intmain(){ BOOK *h = NULL, *p; int i; scanf("%d", &n); h = CreateLink(); PrintLink(h); return0; }