C语言
文章平均质量分 89
ningqingzy
嵌入式开发、测试开发、系统控制
展开
-
STM32基本GPIO操作:跑马灯实验(库函数+寄存器)⭐
一、库函数版本1.初始化以下是初始化PB5端口的代码:// 定义一个类型为GPIO_InitTypeDef,名字叫做GPIO_InitStructure的结构体GPIO_InitTypeDef GPIO_InitStructure;// PORTB时钟使能RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);// 配置结构体GPIO_InitStructureGPIO_InitStructure.GPIO_Pin = GPIO_Pin_转载 2021-02-23 11:17:02 · 2970 阅读 · 0 评论 -
C Primer Plus第六版第十七章编程题目与参考答案⭐
1.修改程序清单17.2,让该程序既能正序也能逆序显示电影列表。一种方法是修改链表的定义,可以双向遍历链表。另一种方法是用递归。#include <stdio.h>#include <stdlib.h>#include <string.h>#define TSIZE 45struct film{ char title[TSIZE]; int rating; struct film *next;};void print_reve原创 2020-12-23 19:20:31 · 687 阅读 · 0 评论 -
C Primer Plus第六版第十六章编程题目与参考答案⭐
1.开发一个包含你需要的预处理器定义的头文件。参考答案://Func.h#ifndef FUNC_H #define FUNC_H #include <stdio.h> #include <stdlib.h> #include <string.h> #define QUIT 0 #define SPACE ' ' #define END 'q' #define SIZE 20#原创 2020-12-23 19:02:24 · 335 阅读 · 0 评论 -
C Primer Plus第六版第十五章编程题目与参考答案⭐
1.编写一个函数,把二进制字符串转换为一个数值。例如,有下面的语句:char * pbin = “01001001”;那么把pbin作为参数传递给该函数后,它应该返回一个int类型的值25。# include <stdio.h># include <limits.h># include <string.h># include <stdlib.h># include <ctype.h> # define SIZE 33 int原创 2020-12-23 17:44:47 · 634 阅读 · 0 评论 -
C Primer Plus第六版第十四章编程题目与参考答案⭐
1.重新编写复习题5,用月份名的拼写代替月份号(别忘了使用strcmp( ))。在一个简单的程序中测试该函数。#include <stdio.h>#include <string.h>#include <ctype.h>#define LEN 12struct month{ char name[10]; char abbrev[4]; int days; int monumb;};const struct month原创 2020-12-22 21:40:19 · 1740 阅读 · 0 评论 -
C Primer Plus第六版第十三章编程题目与参考答案⭐
1、修改程序清单13.1中的程序,要求提示用户输入文件名,并读取用户输入的信息,不使用命令行参数。# include <stdio.h># include <stdlib.h> int main(void){ int ch ; FILE * fp ; char st[100]; unsigned long count = 0 ; printf("Please enter filename:"); scanf("%s" , st); if ((fp =原创 2020-12-22 20:43:47 · 1236 阅读 · 0 评论 -
C Primer Plus第六版第十二章编程题目与参考答案⭐
1.不使用全局变量,重写程序清单12.4。(下面是书中12.4的代码。)#include <stdio.h>int units = 0; //外部变量 void critic(void); int main(void) { extern int units; //可选的重复声明 printf("How many pounds to a firkin of butter?\n"); scanf("%d",&units); while (units != 5原创 2020-12-11 20:13:25 · 507 阅读 · 0 评论 -
C Primer Plus第六版第十一章编程题目与参考答案⭐
1.设计并测试一个函数,从输入中获取下n个字符(包括空白、制表符、换行符),把结果储存在一个数组里,它的地址被传递作为一个参数。#include <stdio.h>#define LEN 10void getnchar(char str[], int n);int main(int argc, char *argv[]){ int i; char input[LEN]; printf("请输入%d个字符(遇EOF停止读取):\n", LEN - 1);原创 2020-12-11 19:12:54 · 594 阅读 · 0 评论 -
C Primer Plus第六版第十章编程题目与参考答案⭐
1.修改程序清单10.7的rain.c程序,用指针进行计算(仍然要声明并初始化数组)。#include <stdio.h>#define MONTHS 12#define YEARS 5int main(void){ int year, month; float subtot, total; const float rain[YEARS][MONTHS] = { {4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4原创 2020-12-11 19:01:07 · 480 阅读 · 0 评论 -
C Primer Plus第六版第九章编程题目与参考答案⭐
1.设计一个函数 min (x,y),返回两个double类型值的较小值。在一个简单的驱动程序中测试该函数。#include <stdio.h>double min(double x,double y); int main() { double a,b; printf("请您输入2个数,中间用英文逗号隔开(按q退出本程序):"); while (scanf("%lf,%lf", &a, &b) == 2) { printf("最原创 2020-12-10 19:12:40 · 491 阅读 · 0 评论 -
C Primer Plus第六版第八章编程题目与参考答案⭐
下面的一些程序要求输入以EOF终止。如果你的操作系统很难或根本无法使用重定向,请使用一些其他的测试来终止输入,如读到&字符时停止。1.设计一个程序,统计在读到文件结尾之前读取的字符数。#include <stdio.h>int main(void){ int ch; int ct = 0; printf("请输入一些字符:\n"); while ((ch = getchar()) != EOF) { ct++;原创 2020-12-07 22:24:23 · 302 阅读 · 0 评论 -
C Primer Plus第六版第七章编程题目与参考答案⭐
1.编写一个程序读取输入,读到#字符停止,然后报告读取的空格数、换行符数和所有其他字符的数量。#include <stdio.h>#define STOP '#'#define SPACE ' ' int main(void){ int ch, space, enter, others; space = enter = others = 0; printf("请输入信息(输入#结束):\n"); while ((ch = getchar()) !=原创 2020-12-07 21:32:22 · 584 阅读 · 0 评论 -
C Primer Plus第六版第六章编程题目与参考答案⭐
1.编写一个程序,创建一个包含26个元素的数组,并在其中储存26个小写字母。然后打印数组的所有内容。#include <stdio.h>#define LEN 26int main(void) { int i; char letters[LEN]; for(i=0; i<LEN; i++) { letters[i] = 'a' + i; } for (i = 0; i < LEN; i++) { printf("%-3c", lette原创 2020-12-06 18:02:03 · 1192 阅读 · 0 评论 -
C Primer Plus第六版第五章编程题目与参考答案⭐
1.编写一个程序,把用分钟表示的时间转换成用小时和分钟表示的时间。使用#define 或者const创建一个表示60的符号常量或const变量。通讨while循环让用户重复输入值,直到用户输入小于或等于0的值才停止循环。#include <stdio.h>#define MINTOHOUR 60 int main() { int minutes,mins,hours; printf("请输入分钟数输入0或负数退出):\n"); scanf("%d",&minutes原创 2020-12-04 22:15:43 · 473 阅读 · 1 评论 -
C Primer Plus第六版第四章编程题目与参考答案⭐
1.编写一个程序,提示用户输入名和姓,然后以“名,姓”的格式打印出来。#include <stdio.h>int main() { char firstname[20]; char lastname[20]; printf("请输入您的姓: "); scanf("%s", &firstname); printf("请输入您的名: "); scanf("%s", &lastname); printf("\n您的名字是:%s,%s",lastname,f原创 2020-12-04 15:26:18 · 673 阅读 · 0 评论 -
C Primer Plus第六版第三章编程题目与参考答案⭐
1.通过试验(即编写带有此类问题的程序观察系统如何处理整数上溢、浮点数上溢和浮点数下溢的情况。#include <stdio.h>int main(){ int a = 2147483647; float b = 3.4E38 * 100.0f; float c = (3.4E-38) / (100.0E100); printf("%d %d %d\n", a, a+1, a+2); //整数上溢 printf("%e\n", b);原创 2020-12-03 22:15:30 · 497 阅读 · 0 评论 -
C Primer Plus第六版第二章编程题目与参考答案
1.编写一个程序,调用一次printf()函数,把你的名和姓打印在一行。再调用一次printf()函数,把你的名和姓分别打印在两行。然后,再调用两次printf()函数,把你的名和姓打印在一行。输出应如下所示(当然要把示例的内容换成你的名字)Gustav Mahler ——第1次打印的内容Gustav ——第2次打印的内容Mahler ——仍是第2次打印的内容Gustav Mahlc ——第3原创 2020-12-01 23:53:21 · 795 阅读 · 0 评论