C语言程序设计现代方法(第二版)课后练习
边学边做
神秘的企鹅
Freshman
展开
-
C语言程序设计现代方法(第二版)Chapter 9
1. 数组排序 #include <stdio.h> int selection_sort (int n, int book[n]) { //n 记录数组长度,由用户输入 int i, j; int max = book[0]; for (i = 0; i < n; i ++) { if (max <= book[i]) { max = book[i]; j = i; } } book[j] = book[n-1];原创 2021-08-22 09:52:53 · 195 阅读 · 0 评论 -
C语言程序设计现代方法(第二版)Chapter 8 续
9.随机步法 #include<stdio.h> #include<stdlib.h> #include<time.h> #include<stdbool.h> #define N 10 char map[N][N]; int i = 0, j = 0; int next_i = 0, next_j=0; void nextstep(int next)//上0 右1 下2 左3 { switch(next) { cas原创 2021-08-15 09:06:33 · 119 阅读 · 0 评论 -
C语言程序设计现代方法(第二版)Chapter 8
1.显示重复数字 #include <stdbool.h> #include <stdio.h> int main(void) { bool digit_seen[10] = {false}; int digit; long n; printf("Enter a number: "); scanf("%ld", &n); printf("Repeated digit(s):"); while (n > 0) { digit = n %原创 2021-08-09 14:05:07 · 266 阅读 · 0 评论 -
C语言程序设计现代方法(第二版) Chapter 6
第六章 1.找出用户输入的最大数 #include <stdio.h> #include <stdlib.h> int main(void) { float n, max = 0.00f; printf("Command: 0 = print max \n\n "); for (;n > 0;) { printf("Enter a number: "); scanf("%f", &n); if (n > max) {原创 2021-08-06 19:08:37 · 128 阅读 · 0 评论 -
C语言程序设计现代方法(第二版)Chapter 5
第五章 1.确定一个数的位数 #include <stdio.h> #include <stdlib.h> int main(void) { int x, y; printf("Enter a number : "); scanf("%d", &x); y = x; int i; while (x != 0) { x /= 10; i ++; } printf("The number %d ha原创 2021-08-06 12:31:02 · 189 阅读 · 0 评论 -
C语言程序设计现代方法(第二版)Chapter 4
第四章 1.用户输入一个两位数,按逆序打印这个数 #include <stdio.h> #include <stdlib.h> int main(void) { int x; printf("Enter a two_digit number :"); scanf("%d", &x); int a, b; a = x % 10; b = x / 10; printf("The reversal is : %d%d", a, b); sys原创 2021-08-06 12:19:04 · 177 阅读 · 0 评论 -
C语言程序设计现代方法(第二版)Chapter 3
第三章 1.以月/日/年格式接受用户输入信息,并以年月日格式输出 #include <stdio.h> int main(void) { int mm, dd, yyyy; printf("Enter a date (mm/dd/yyyy) :"); scanf("%d/%d/%d", &mm, &dd, &yyyy); printf("You enter the date %d%02d%02d \n", yyyy, dd, mm); ret原创 2021-08-06 12:08:47 · 182 阅读 · 0 评论 -
C语言程序设计现代方法(第二版)Chapter 2
第二章 1.使用printf在屏幕上显示下面图形: #include <stdio.h> int main(void) { printf(" * \n"); printf(" * \n"); printf(" * \n"); printf(" * * \n"); printf(" * * \n"); printf(" * * \n");原创 2021-08-06 11:47:15 · 369 阅读 · 0 评论