为了账号安全,请及时绑定邮箱和手机立即绑定

作业社区

探索学习新天地,共享知识资源!

0 提交作业
0 布置作业
0 满分作业
得分 100
讨论题

学渣小白 的学生作业:

#include #define debug 0 #define DEBUG_PRINT(…) do { if(debug) printf(VA_ARGS); } while(0) int main(void) { //DEBUG_PRINT (“Simplified debugging: temp=% d, formula calculation:% d \n”, temp, temp+10); int i=6; int factorial=1; while(–i) { factorial*=i; DEBUG_PRINT (“i=%d\n”,i); DEBUG_PRINT (“factorial=%d\n”,factorial); DEBUG_PRINT("\n*************delimiter**************\n"); } printf("factorial=%d\n",factorial); return 0; } linux@linux:~/test01$ gcc 1j8practicer.c linux@linux:~/test01$ ./a.out factorial=120 linux@linux:~/test01$ #include #define debug 1 #define DEBUG_PRINT(…) do { if(debug) printf(VA_ARGS); } while(0) int main(void) { //DEBUG_PRINT (“Simplified debugging: temp=% d, formula calculation:% d \n”, temp, temp+10); int passwd = 0,num_input=0; int correct_password=123456; do { if (num_input>=3) { printf(“GAME OVER!” “\n”); return 1; }else if (num_input!=0) { printf(“You have already made mistakes with your password %d times, and there are %d more chances. Keep it up!\n”,num_input,3-num_input ); } printf(“Please enter the password” “\n”); scanf("%d", &passwd); num_input++; // 清除输入缓冲区 while (getchar() != ‘\n’); // 读取并丢弃直到换行符的所有字符 }while (correct_password!=passwd); // 尊敬的艾欧尼亚最强王者,本网吧欢迎您! printf("Dear Ionia, the strongest king of K, our internet cafe welcomes you!" "\n"); return 0; } linux@linux:~/test01$ gcc 1j81practicer.c linux@linux:~/test01$ ./a.out Please enter the password dfdsf2134 You have already made mistakes with your password 1 times, and there are 2 more chances. Keep it up! Please enter the password sdfds23434 You have already made mistakes with your password 2 times, and there are 1 more chances. Keep it up! Please enter the password 4324155 GAME OVER! linux@linux:~/test01$ ./a.out Please enter the password fsgdfdsa You have already made mistakes with your password 1 times, and there are 2 more chances. Keep it up! Please enter the password 123456 Dear Ionia, the strongest king of K, our internet cafe welcomes you! linux@linux:~/test01$

得分 100
学习任务

残梦ming 的学生作业:

#include #include #include #include #include #include #define BUFFER_SIZE 1024 int main(){ pid_t cpid; int pipefd[2]; int ret; ret = pipe(pipefd); // 创建管道后,内核会将文件描述符存储到数组 if(ret == -1){ perror("[ERROR] pipe():"); exit(EXIT_FAILURE); } cpid = fork(); if(cpid == -1){ perror("[ERROR] fork():"); exit(EXIT_FAILURE); }else if(cpid == 0){ // 1.从管道中读取数据(fork()返回0子进程) close(pipefd[1]); // 关闭子进程写端文件描述符 ssize_t rbytes; char buffer[BUFFER_SIZE]; while(1){ memset(buffer, 0, BUFFER_SIZE); // 2.参1:文件描述符 参2:数据缓冲区 参3:能够读取的最大字节数 rbytes = read(pipefd[0], buffer, sizeof(buffer)); // 管道无数据,阻塞 if(rbytes == -1){ perror("[ERROR] read():"); close(pipefd[0]); exit(EXIT_FAILURE); }else if(rbytes == 0){ printf("父进程关闭,子进程退出.\n"); break; } printf("buffer: %s\n", buffer); fflush(stdout); if(strcmp(buffer, "quit") == 0){ printf("子进程退出.\n"); break; } } close(pipefd[0]); exit(EXIT_SUCCESS); }else if(cpid > 0){ close(pipefd[0]); ssize_t wbytes; char buffer[BUFFER_SIZE]; while(1){ memset(buffer, 0, sizeof(buffer)); printf("请输入字符串:"); fflush(stdout); scanf("%s", buffer); if(strcmp(buffer, "quit") == 0){ exit(EXIT_SUCCESS); break; } wbytes = write(pipefd[1], buffer, strlen(buffer)); if(wbytes == -1){ perror("[ERROR] write()"); wait(NULL); close(pipefd[1]); exit(EXIT_FAILURE); } if(strcmp(buffer, "quit") == 0){ break; } } close(pipefd[1]); wait(NULL); } return 0; } 【图片】

得分 100
学习任务

学渣小白 的学生作业:

#include #include #define debug 1 #define DEBUG_PRINT(…) do { if(debug) printf(VA_ARGS); } while(0) // 从键盘输入一个成绩,判断成绩的等级 // 如果成绩 score< 0 或 score> 100 则提示用户输入的是非法成绩 // 如果是: // [0-60) 则输出 E等级 // [60-70) 则输出 D等级 // [70-80) 则输出 C等级 // [80-90)则输出 B等级 // [90-100] 则输出 A等级 。 // 要求用switch语句写一段代码实现上述的功能。 int main(void) { //DEBUG_PRINT (“Simplified debugging: temp=% d, formula calculation:% d \n”, temp, temp+10); int score; printf(“please input a score:”); scanf("%d",&score); if(score100) { printf(“WARRING:The input is an illegal grade!” “\n”); raise(2); } printf(“Legitimate grades are being calculated” “\n”); switch (score/10) { case 0: case 1: case 2: case 3: case 4: case 5: printf(“The grade is E level” “\n”); break; case 6: printf(“The grade is D level” “\n”); break; case 7: printf(“The grade is C level” “\n”); break; case 8: printf(“The grade is B level” “\n”); break; case 9: printf(“The grade is A level” “\n”); break; case 10: printf(“The grade is A level” “\n”); break; default: printf(“Unknown error.\n”); // 防御性编程,理论上不会执行 raise(2); break; } return 0; } linux@linux:~/test01$ gcc 1j6practicer.c linux@linux:~/test01$ ./a.out please input a score:380 WARRING:The input is an illegal grade! linux@linux:~/test01$ ./a.out please input a score:78 Legitimate grades are being calculated The grade is C level linux@linux:~/test01$ ./a.out please input a score:99 Legitimate grades are being calculated The grade is A level linux@linux:~/test01$

得分 99
学习任务

学渣小白 的学生作业:

#include #define debug 1 #define DEBUG_PRINT(…) do { if(debug) printf(VA_ARGS); } while(0) // int year; // 要求用户从键盘输入一个年数赋值给year,然后判断year是不是闰年。 // 若是闰年,输出"XX year is leap year!",否则输出"XX year is not year" // 闰年的条件: // [1]能够被4整除,并且不能被100整除 // [2]能够被400整除. 以上条件满足一条,则为闰年。 // int main(void) { // //DEBUG_PRINT (“Simplified debugging: temp=% d, formula calculation:% d \n”, temp, temp+10); // int year; // printf(“please input a year:”); // scanf("%d",&year); // if(year%4!=0) { // printf("%d year is not leap year!\n",year); // }else if (year%100!=0) { // printf("%d year is leap year!\n",year); // }else if (year%400!=0) { // printf("%d year is not leap year!\n",year); // }else{ // printf("%d year is leap year!\n",year); // } // return 0; // } int main(void) { //DEBUG_PRINT (“Simplified debugging: temp=% d, formula calculation:% d \n”, temp, temp+10); int year; printf(“please input a year:”); scanf("%d",&year); if(year%40&&year%100!=0||year%4000) { printf("%d year is leap year!\n",year); }else{ printf("%d year is not leap year!\n",year); } return 0; } linux@linux:~/test01$ gcc 1j4practicer.c linux@linux:~/test01$ ./a.out please input a year:1800 1800 year is not leap year! linux@linux:~/test01$ ./a.out please input a year:2000 2000 year is leap year!

得分 100
讨论题

慕工程6300203 的学生作业:

#include #include #include typedef int data_type; typedef struct node { data_type data; struct node *next; } link_node_type; link_node_type *create_empty_link_list() { link_node_type *head = (link_node_type *)malloc(sizeof(link_node_type)); head->next = NULL; return head; } /** * 有序插入 * @param head * @param data */ void insert_order_linklist(link_node_type *head, const data_type data) { link_node_type *p = head; link_node_type *new_node = (link_node_type *)malloc(sizeof(link_node_type)); new_node->data = data; while (p->next != NULL && p->next->data < data) { p = p->next; } new_node->next = p->next; p->next = new_node; } /** * 尾节点插入 * @param head * @param data */ void insert_tail_linklist(link_node_type *head, const data_type data) { link_node_type *p = head; link_node_type *new_node = (link_node_type *)malloc(sizeof(link_node_type)); new_node->data = data; while (p->next != NULL) { p = p->next; } new_node->next = p->next; p->next = new_node; } /** * 判断是否为空 * @param head * @param data */ int is_empty_linklist(const link_node_type *head) { return head->next == NULL ? 1 : 0; } /** * 删除和data相同的节点 * @param head * @param data */ int delete_data(link_node_type *head, const data_type data) { if (is_empty_linklist(head)) return -1; link_node_type *p = head; link_node_type *q = NULL; int i = 0; while (p->next != NULL) { if (p->next->data == data) { q = p->next; p->next = p->next->next; free(q); i++; } else { p = p->next; } } printf("%d node is deleted\n", i); return 0; } void print_link_list(link_node_type *head) { const link_node_type *temp = head; while (temp != NULL && temp->next != NULL) { printf("%d ", temp->next->data); temp = temp->next; } printf("\n"); } int main() { link_node_type *head = create_empty_link_list(); data_type data; const int n = 9; printf("please input your data:"); for (int i = 0; i < n; i++) { scanf("%d", &data); insert_tail_linklist(head, data); } delete_data(head, 3); print_link_list(head); free(head); head = NULL; return 0; }

首页上一页1234567下一页尾页
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号