摘要: 编写程序,使用while语句求和sum=1+3+5+7+……+21. #include<stdio.h> main(){ int i=1,sum=0; while(i<=21){ if(i%2!=0) sum+=i; i++; } printf("sum=%d\n",sum); } 编写程序,使用w 阅读全文
posted @ 2021-11-07 22:06 风吹过半岛 阅读(70) 评论(0) 推荐(0)
摘要: 1.编写程序判断n是正数还是负数。 #include<stdio.h> main(){ float n; printf("输入一个数\n"); scanf("%f",&n); if(n>0) printf("%f是正数"); else if(n==0) printf("%f既不是正数也不是负数"); 阅读全文
posted @ 2021-11-07 22:03 风吹过半岛 阅读(46) 评论(0) 推荐(0)
摘要: 使用switch-case语句编写代码。 #include<stdio.h> main(){ int mark; printf("输入学生成绩(0-100):\n"); scanf("%d",&mark); switch(mark/10){ case 10: case 9:printf("A\n") 阅读全文
posted @ 2021-11-07 22:01 风吹过半岛 阅读(14) 评论(0) 推荐(0)