随笔分类 -  C primer习题

摘要:输入一个正整数 显示所有小于它的素数 PS:1.此程序必须加入flag标签,用以检查输入的数字是否进入循环(如果不加 则数字2 3 将无法进入循环 从而被遗漏) 2.加入标签后,以前的代码是在内侧循环中 如果1%num!=0 就输出为质数,但是产生的问题是无法将2 3输出,有了flag后,应该充分利 阅读全文
posted @ 2017-06-11 10:06 ryosukeli 阅读(129) 评论(0) 推荐(0)
摘要:1.使用一个switch语句做选项时,如果希望能退出程序,可以用goto语句。 其他时候不推荐用goto语句。 改进如下: 2.改进主要集中在输入选项的显示,减少了代码量,并且使得程序可读性增强。每次进入循环都会显示选项。下一步改进将集中于在get_choice函数中实现对输入的控制,对不正确的输入 阅读全文
posted @ 2017-06-10 15:53 ryosukeli 阅读(199) 评论(0) 推荐(0)
摘要:#include <stdio.h>#define SIZE 8int main(void){ double num_1[SIZE],num_2[SIZE]; int index1,index2; printf("Please enter 8 numbers:"); for (index1=0;in 阅读全文
posted @ 2017-05-18 10:56 ryosukeli 阅读(130) 评论(0) 推荐(0)
摘要://编写程序包含8个元素的int类型数组,用for循环设置数组元素,用do while循环显示元素值。 #include <stdio.h>int main(void){ int num[8],index,i,pow; for (index=0,i=0,pow=1;index<=7;index++) 阅读全文
posted @ 2017-05-17 15:50 ryosukeli 阅读(117) 评论(0) 推荐(0)
摘要:6.07 让用户输入一个单词,并倒序打印这个单词 #include <stdio.h>#include <string.h>int main(void){ char word[20]; size_t size; int index; printf("Please enter a word:"); s 阅读全文
posted @ 2017-05-17 11:23 ryosukeli 阅读(123) 评论(0) 推荐(0)