当前位置:首页 > 计算概论2009期末考试试题
2.
void main(void) {
static char s[]=\wbc\; int m, a=0, b=0, c=0;
for (m=0;s[m]!=?\\0?; m++)
switch (s[m]) {
case 'c' : c++ ; case 'b' : b++ ; default: a++; }
printf(\ }
五 阅读下列程序,在空格处填入适当内容,使程序完整。(每空2分,30分) 1.用选择法对数组中的10个字符按由大到小排序。 void sort(char a[ ], int n) { int i,j,k;
char t;
for (i=0;i main( ) { char s[10]; int i; 5 for(i=0;i<10;i++) scanf(\ (3) ; printf(\ for(i=0;i<10;i++) printf(\(4) ); printf(\} (1) (2) (3) (4) 2.用“起泡法”对输入的10个字符排序后按从小到大的次序输出 #define N 10 char str[N]; void sort(char str[];) main() { int i, flag; for(i=0;i<10;i++) scanf(\ sort( (5) ); for(i=0;i void sort(char str[N];) { int i,j; char t; for (j=1;j t=str[i]; (7) ; (8) ; } } (5) (6) (7) (8) 6 3.用单向循环链表求解约瑟夫环问题: 用户输入M,N值,从1至N开始顺序循环数数,每数到M输出该数值,直至全部输出。(注: 单向循环链表的尾节点指针指向头节点。) #include int num; struct node *next; }; struct node * circle_create(int n) { struct node *p_header = NULL; struct node *p_node = NULL; struct node *p_tail = NULL; int num; (9) ; if (p_node ==NULL) return NULL; p_node->num = 1; p_header = p_node; p_header->next = p_header; p_tail = p_node; for (num=2; num <= n; num++) { p_node = (struct node *) malloc(sizeof(struct node)); p_node->num = num; p_node->next = p_header;; (10) ; p_tail = p_node; } 7 return p_header; } void main() { int n, m; struct node *p_node, *p_header, *p_temp; printf(\ scanf(\ printf(\key is : %d \\n\ (11) ; p_node= p_header; while ( (12) ) { int i = 1; for (; i < m - 1; i++) { (13) ; } printf(\ p_temp = p_node->next; (14) ; (15) ; free(p_temp); } printf(\ free(p_header); } (9) (10) (11) (12) (13) (14) (15) 8
共分享92篇相关文档