最新C语言简单编程题.doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《最新C语言简单编程题.doc》由会员分享,可在线阅读,更多相关《最新C语言简单编程题.doc(42页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精品资料C语言简单编程题.题目:1.编写一个程序,要求输入一个ASCII码值(比如66), 然后输出相应的字符(比如输入66,输出B)。#include#include main() int i, j; char c; printf(输入一个ASCII码值:n); scanf(%d, &i); while(1) if(i = 0) printf(输出相对应的字符:n); c=toascii(i); printf(%cn, c); printf(继续输入一个数:n); scanf(%d, &i); else printf(结束); break; return 0;2.功能描述:编写函数,实现对1
2、0个整数按由小到达排序,在主函数中调用此函数。*要 求:完成至少3个函数分别实现插入排序(Insertion Sort)、选择排序、冒泡排序()#include#define M 10void insert(int a, int n);void choice(int a, int n);void BubbleSort(int a, int n);void print(int a,int n); void main() int aM, i; printf(请输入%d个整数:n, M); for(i = 0; i M; i+) scanf(%d, &ai); printf(请输出%d个整数:n,
3、M); for(i = 0; i M; i+) printf(%d , ai); printf(n); insert(a, M); /插入排序 print(a, M); printf(请输入%d个整数:n, M); for(i = 0; i M; i +) scanf(%d, &ai); printf(请输出%d个整数:n, M); for(i = 0; i M; i+) printf(%d , ai); printf(n); choice(a, M); /选择排序 print(a, M); printf(请输入%d个整数:n, M); for(i = 0; i M; i +) scanf(%
4、d, &ai); printf(请输出%d个整数:n, M); for(i = 0; i M; i+) printf(%d , ai); printf(n); BubbleSort(a, M); /冒泡排序 print(a, M);void insert(int a,int n) /插入排序 int i, j, k, temp; for(i = 1; i 0; j-) if(aj aj-1) temp = aj; aj = aj-1; aj-1 = temp; else break; void choice(int a, int n) /选择排序 int i, j, temp = 0, t=0
5、; for(i = 0; i n; i+) t = i; for(j = i + 1; j aj) t = j; temp = ai; ai = at; at = temp; void BubbleSort(int a, int n) int i, j, temp; for(i = 0; i n - 1; i+) for(j = 0; j aj+1) temp = aj; aj = aj+1; aj+1 = temp; void print(int a,int n) int i; printf(输出排序后的整数:n); for(i = 0; i 10; i +) printf(%d ,ai);
6、 printf(n);3. 已知head指向一个带头结点的单向链表,链表中每个结点包含数据域(data)和指针域(next)。 请编写函数实现如图所示链表逆置。要求: 不开辟任何额外的链表结点空间,实现链表的就地逆置考察: 对链表结构的基本操作#include#include#include#include#define LEN sizeof(struct sth)struct sth char a20; struct sth *next;struct sth *creat(void);struct sth *exchange(struct sth *creat);void print(str
7、uct sth *head);void free1(struct sth *head);void main(void) struct sth *head; printf(请输入链表: n); head = creat(); printf(请输出链表: n); print(head); exchange(head); printf(输出逆置的链表: n); print(head); free1(head); struct sth *creat(void) struct sth *head = NULL; struct sth *p1, *p2; char input10=0; / p1 = p2
8、 = (struct sth*)malloc(LEN); if(p1 =(struct sth*)malloc(LEN)= NULL) printf(内存不足,请稍后再试!n); return 0; else head = p1; p2 = head; printf(请输入相关信息:n); while(gets(input) != 0 & input0 != 0) if(p1 = (struct sth*)malloc(LEN)= NULL) printf(内存不足,请稍后再试!n); return 0; else p2 - next = p1; p2 = p1; p1 - next = NU
9、LL; strcpy(p1 - a, input); printf(请输入数据(空行则退出链表的输入):n); return (head); struct sth *exchange(struct sth *head) struct sth *p1, *p2, *p3; p1=head-next; ; p2=p1-next; p3=p2-next; p2-next = p1; p1-next = NULL; p1 = p2; p2 = p3; while(p2!=NULL) p3 = p2 - next; p2 - next = p1; p1 = p2; p2 = p3; / p2-next
10、= p1; head - next = p1; return head;void print(struct sth *head)struct sth *p1;p1 = head-next;if(head!= NULL)while(p1 != NULL)printf(%sn, p1-a);p1 = p1-next; void free1(struct sth *head) struct sth *p1, *p2; if(head!=NULL) p1 = head-next; if(p1!=NULL) p2 = p1-next; free(p1); p1 = p2; 功能描述:4.有两个链表a和b
11、,设结点中包含学号和姓名。 从a链表中删去与b链表中相同学号的结点。#include#include#include#define LEN sizeof(struct student)struct student char num10; char name10; struct student *next;struct student*creat(void);void print(struct student *heada);void free1(struct student *heada);struct student*found(struct student *heada, struct s
12、tudent *headb);int main(void) struct student *head1, *head2; printf(请输入链表a:n); head1 = creat(); print(head1); printf(请输入链表b:n); head2 = creat(); print(head2); printf(输出删除后的链表a:n); found(head1, head2); free1(head1); free1(head2); return (0);struct student *creat(void) int n = 0, i; char num2 = 0; str
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 最新 语言 简单 编程
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内