![](https://img-blog.csdnimg.cn/20190927151132530.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
C语言程序设计:现代方法(第二版·修订版)
该专栏收录的是这本书“编程题”的答案(自己写的,有错误请指正!)
碰碰狗
计算机专业在读学生
展开
-
第8章 数组
假设:int a[10];对于原表达式 sizeof(a) / sizeof(a[0]) ,如果数组的类型变更了,比如从int变成double,对其没有影响但如果是 sizeof(a) / sizeof(int) ,需要手动变更为:sizeof(a) / sizeof(double) ,会比较麻烦。原创 2023-04-05 16:41:23 · 115 阅读 · 0 评论 -
第2章 C语言基本概念
《C语言程序设计:现代方法》第2章练习题+编程题答案原创 2023-01-19 12:35:28 · 119 阅读 · 0 评论 -
第3章 格式化输入/输出
C语言程序设计现代方法答案原创 2023-01-19 16:45:36 · 173 阅读 · 0 评论 -
第4章 表达式
练习题+编程题答案原创 2023-01-20 12:10:39 · 85 阅读 · 0 评论 -
第5章 选择语句
编程题+练习题答案原创 2023-01-28 16:46:44 · 98 阅读 · 0 评论 -
第6章 循环
《C语言程序设计:现代方法》练习题+编程题答案原创 2023-01-29 17:05:06 · 149 阅读 · 0 评论 -
第7章 基本类型
《C语言程序设计:现代方法》第7章练习题+编程题答案原创 2023-04-05 14:10:26 · 81 阅读 · 0 评论 -
8---1
#include<stdio.h>#include<stdbool.h>int main(void){ bool digit_seen[10] = { false }, a[10] = { false }; int digit, n; printf("PLease enter a number:"); scanf_s("%d", &n); while (n>0) { digit = n % 10;...原创 2021-09-22 22:03:38 · 95 阅读 · 0 评论 -
8---2
#include<stdio.h>int main(void){ int a[10] = {0}; int digit, n; printf("PLease enter a number:"); scanf_s("%d", &n); while (n>0) { digit = n % 10; a[digit]++; n /= 10; } printf("Digi...原创 2021-09-22 22:24:54 · 86 阅读 · 0 评论 -
8---3
#include<stdio.h>#include<stdbool.h>int main(void){ bool digit_seen[10] = { false }, a[10] = { false }; int digit, n = 1; while (1) { printf("PLease enter a number:"); scanf_s("%d", &n); if (n>...原创 2021-09-22 22:32:10 · 55 阅读 · 0 评论 -
8---4
#include<stdio.h>#define SIZE ((int) (sizeof(a)/sizeof(a[0])))int main(void){ int a[10]; printf("PLease enter a series of number:"); for (int i = 0; i < SIZE; i++) { scanf_s("%d", &a[i]); } printf("In rev...原创 2021-09-23 19:52:11 · 76 阅读 · 0 评论 -
8---5
#include<stdio.h>#define NUM_RATES ((int) (sizeof(value)/sizeof(value[0])))#define INITIAL_BALANCE 100.00int main(void){ int i, low_rate, num_year, year; double sum = 0; double value[5]; printf("PLease enter interest rate:");...原创 2021-09-23 19:40:18 · 78 阅读 · 0 评论 -
8---6
#include<stdio.h>#include<ctype.h>#define N 50int main(void){ char ch, str[N] = { 0 }; printf("Eter message: "); for (int i = 0; (ch = getchar()) != '\n'; i++) { str[i] = ch; } printf("In B1FF-speak: "); for (int i = 0; i <.原创 2021-12-13 20:49:35 · 1353 阅读 · 0 评论 -
8---7
#include<stdio.h>int main(void){ int m[5][5]; for (int i = 0; i < 5; i++) { printf("Enter row %d:", i+1); for (int j = 0; j < 5; j++) { scanf_s("%d", &m[i][j]); printf("\n");...原创 2021-09-23 20:43:47 · 72 阅读 · 0 评论 -
8---8
#include<stdio.h>int main(void){ int m[5][5]; int min, max; for (int i = 0; i < 5; i++) { printf("Please enter %d student's grade for five courses:", i + 1); for (int j = 0; j < 5; j++) { scanf_s("%d", &m[i][j]); print..原创 2021-12-13 21:15:06 · 595 阅读 · 0 评论 -
8---9
#include<stdio.h>#include<stdlib.h>#include<time.h>#include<stdbool.h>int main(void){ int step, row, col; const char alpha_code[26] = { 'a','b','c','d','e','f','g','h','i', 'j','k','l','m','n','o','p','q','r', .原创 2021-12-24 13:14:46 · 380 阅读 · 0 评论 -
8---10
#include<stdio.h>int main(void){ int hour, minute, time, d; int start_hour[8] = { 8 * 60, 9 * 60 + 43,11 * 60 + 19 ,12 * 60 + 47 ,14 * 60,15 * 60 + 45, 19 * 50 ,21 * 60 + 45 }; printf("Please enter a 24-hour time:"); scanf_s("%d:%...原创 2021-09-24 08:56:33 · 79 阅读 · 0 评论 -
8---11
#include <stdio.h>int main(void){ int i = 0; char ch[15]; printf("Please enter your phone number:"); while ((ch[i] = getchar()) != '\n') { i++; } for (int i = 0; i < 15; i++) { switch (ch[i]...原创 2021-09-24 09:26:11 · 72 阅读 · 0 评论 -
8---12
#include<stdio.h>#include<ctype.h>int main(void){ int a[26] = { 1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10 }; int sum = 0; char ch; while ((ch = getchar())!= '\n') {.原创 2021-12-19 15:12:10 · 171 阅读 · 0 评论 -
8---13
#include <stdio.h>int main(void){ char ch[20] = { 0 }; char n1, n2; int i = 0, j = 0; printf("Please enter a first and last name:"); while ((ch[i] = getchar()) != '\n') { i++; } printf("You enterd the name...原创 2021-09-24 09:45:51 · 70 阅读 · 0 评论 -
8---14
#include<stdio.h>#include<stdlib.h>#define N 50void print_word(char* str, int i, int j);int main(void){ char ch; char str[N] = { ' ' }; printf("Eter a sentence: "); ch = getchar(); for (int i = 1; i < N && ch != '.' .原创 2021-12-19 14:19:55 · 99 阅读 · 0 评论 -
8---15
#include<stdio.h>#include<ctype.h>#include<stdbool.h>#define N 80int main(void){ char str[N] = { 0 }; char ch; int n; printf("Enter shift amount: "); scanf_s("%d", &n); printf("Enter message to be encrypted: "); ch = .原创 2021-12-19 14:54:17 · 181 阅读 · 0 评论 -
8---16
见9-P-4!原创 2021-09-25 20:18:58 · 63 阅读 · 0 评论 -
8---17
#include<stdio.h>#include<stdlib.h>#include<stdbool.h>int main(void){ int n; printf("This program creates a magic square of a specified size.\n"); printf("The size must be odd number between 1 and 99.\n"); printf("Enter size of .原创 2021-12-20 20:42:43 · 164 阅读 · 0 评论 -
9---1
#include<stdio.h>void selection_sort(int n, int a[]);int main(void){ const int N = 5; int a[5]; printf("Please enter your numbers:"); for (int i = 0; i < N; i++) { scanf_s("%d", &a[i]); } (void)select...原创 2021-09-25 16:10:24 · 154 阅读 · 0 评论 -
9---2
#include<stdio.h>double calculator(double income);int main(void){ double income, tax; printf("Please enter your income:"); scanf_s("%lf", &income); tax = calculator(income); printf("Your tax is:%.2f", tax); return...原创 2021-09-25 16:26:16 · 72 阅读 · 0 评论 -
9---3
#include<stdio.h>#include<stdlib.h>#include<time.h>#include<stdbool.h>void generate_random_walk(char walk[10][10]);void print_array(char walk[10][10]);const char alpha_code[26] = { 'a','b','c','d','e','f','g','h','i', .原创 2021-12-27 11:33:08 · 61 阅读 · 0 评论 -
9---4
#include<stdio.h>#include<stdbool.h>#include<ctype.h>void read_word(int counts[]);bool equal_array(int counts1[], int counts2[]);int main(void){ int counts1[26] = { 0 }; int counts2[26] = { 0 }; int result; printf...原创 2021-09-25 20:19:52 · 92 阅读 · 0 评论 -
9---5
#include<stdio.h>#include<stdlib.h>#include<stdbool.h>void create_magic_square(int n,int a[99][99]);void print_magic_square(int n, int a[99][99]);int main(void){ int n; printf("This program creates a magic square of a specifie.原创 2021-12-27 12:15:24 · 102 阅读 · 0 评论 -
9---6
#include<stdio.h>int caculator(int x);int main(void){ int x, total; printf("Please enter a number:"); scanf_s("%d", &x); total = caculator(x); printf("%d", total); return 0;}int caculator(int x){ return 3 ...原创 2021-09-25 20:28:16 · 57 阅读 · 0 评论 -
9---7
#include<stdio.h>int power(int x, int n);int main(void){ int x, n, total; printf("Please enter x:"); scanf_s("%d", &x); printf("Please enter n:"); scanf_s("%d", &n); total = power(x, n); printf("%d", total);...原创 2021-09-25 21:07:33 · 146 阅读 · 0 评论 -
9---8
#include<stdio.h>#include<stdlib.h>#include<time.h>#include<stdbool.h>int roll_dice(void);bool play_game(void);int main(void){ int win = 0, lose = 0; bool first_game = true; while (1) { if (first_game==false) { .原创 2021-12-27 15:47:39 · 159 阅读 · 0 评论 -
11---1
#include<stdio.h>void pay_amount(int dollars, int* twenties, int* tens, int* fives, int* ones);int main(void){ int dollars, twenties, tens, fives, ones; printf("Please enter a dollar amount:"); scanf_s("%d", &dollars); (voi...原创 2021-09-27 20:15:48 · 92 阅读 · 0 评论 -
11---2
#include<stdio.h>void find_closet_flight(int time, int* departure_time);int main(void){ int hour, minute, time, d; printf("Please enter a 24-hour time:"); scanf_s("%d:%d", &hour, &minute); time = hour * 60 + minute; ...原创 2021-09-27 20:46:15 · 54 阅读 · 0 评论 -
11---3
#include<stdio.h>void reduce(int num, int denom, int* redueced_num, int* reduced_denom);int main(void){ int num, denom, reduced_num, reduced_denom; printf("Please enter two integer:"); scanf_s("%d/%d", &num, &denom); (v...原创 2021-09-27 20:32:08 · 58 阅读 · 0 评论 -
11---4
#include<stdio.h>#include<stdlib.h>#include<stdbool.h>#define NUM_RANKS 13#define NUM_SUITS 4#define NUM_CARDS 5void read_cards(int* num_in_rank, int* num_in_suit);void analyze_hand(int* num_in_rank, int* num_in_suit, bool* str.原创 2021-12-31 13:01:45 · 73 阅读 · 0 评论 -
12---1
(a)nclude<stdio.h>#define N 100int main(void){ char a[N] = {'0'}; int n, i = 0; printf("Please enter a message:"); while ( (n=getchar() )!='\n') { a[i] = n; i++; } for (int j = N;j>=0&&a...原创 2021-10-03 15:33:45 · 75 阅读 · 0 评论 -
12---2
#include<stdio.h>#include<ctype.h>#define N 50int main(void){ char str[N] = { 0 }; char ch; printf("Enter a message: "); for (int i = 0; i < N && (ch = getchar()) != '\n';) { if ((ch >= 'A' && ch <= 'Z') .原创 2021-12-29 12:12:23 · 51 阅读 · 0 评论 -
12---3
#include<stdio.h>#define N 100int main(void){ char a[N] = { '0' }; char* p; printf("Please enter a message:"); for (p = a; (*p = getchar()) != '\n'; p++) { } for (p = a + N - 1; p >= a && *p != '0'; p--) { printf("%c", *p.原创 2021-12-29 11:00:59 · 99 阅读 · 0 评论 -
12---4
#include<stdio.h>#include<ctype.h>#define N 50int main(void){ char str[N] = { 0 }; char ch; char* p, * q; printf("Enter a message: "); for (p=str; p < str+N && (ch = getchar()) != '\n';) { if ((ch >= 'A' &&.原创 2021-12-29 12:16:02 · 322 阅读 · 0 评论