第一范文网 - 专业文章范例文档资料分享平台

C语言基础练习题(含答案)

来源:用户分享 时间:2025/5/25 5:30:15 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

第二章 选择结构 ·33·

printf(”please input the year to jude whether it is a leap

year:”);

scanf(”%d”,&year);

if (year@0==0) flag=1; else if (【1】) flag=1; else 【2】;

if (flag) printf(”%d is a leap year\\n”,year); else printf(”%d is not a leap year!\\n”,year); }

14.以下程序是对用户输入的字母进行大小写转换。请在【】内填入正确内容。

#include ”stdio.h” main() {

char ch;

printf(”please input a letter:”); scanf(”%c”,&ch); if (【1】) ch=ch+32;

else if (ch>=’a’ && ch<=’z’) 【2】;

printf(” the converted letter is: %c\\n”,ch); }

15.以下程序是对从键盘输入的任何三个整数,求出其中的最小

值。请在【】内填入正确内容。 #include ”stdio.h” main() {

int a,b,c,min;

printf(”please input three numbers:”); scanf(”%d%d%d”,&a,&b,&c);

第二章 选择结构 ·34·

if (【1】) min=b; else

min=a; if (min>c)

【2】;

printf(”min=%d\\n”,min);

} 16.以下程序实现这样的功能:商店卖西瓜,10斤以上的每斤0.15

元,8斤以上的每斤0.3元,6斤以上的每斤0.4元,4斤以上的每斤0.6元,4斤以下的每斤0.8元,从键盘输入西瓜的重量和顾客所付钱数,则输出应付款和应找钱数。请在【】内填入正确内容。 #include ”stdio.h” main() {

float weight, money, rate;

printf(”the paid money of the client is:”); scanf(”%f”,&money);

printf(”the weight of the watermelon is:”); scanf(”%f”,&weight); if (【1】)

rate=0.15; else if (weight>8) rate=0.3; else if (weight>6) 【2】; else if (weight>4)

rate=0.6;

【3】

rate=0.8;

第二章 选择结构 ·35·

printf(”the account payable of the watermelon is %f\\n”,

weight*rate);

printf(”the change for client is %f\\n”,money-weight*rate); }

17.以下程序段的运行结果是________。

#include ”stdio.h” main() {

char ch1=’a’,ch2=’A’; switch (ch1) { case ’a’:

switch (ch2)

{case ’A’: printf(”good!\\n”); break; case ’B’: printf(”bad!\\n”); break; }

case ’b’: printf(”joke\\n”); } }

18.根据以下函数关系,对输入的每个x值,计算出相应的y值。

请在【】内填入正确内容。

x y x<0 0 0<=x<1x 0 10<=x<10 20 20<=x<-0.5x+240 0 #include ”stdio.h” main() {

第二章 选择结构 ·36·

int x, rate;

float y;

printf(”please input the value of x:”); scanf(”%d”,&x); if (【1】) rate= -1; else rate=【2】; switch(rate)

{ case –1: y=0; break;

case 0: y=x; break; case 1: y=10; break; case 2:

case 3: y=-0.5*x+20; break; default: y= -2;

}

if (【3】) printf(”y=%f\\n”,y);

else printf(”the value of x is invalid!\\n”);

}

19.以下程序实现的功能是:从键盘输入某年某月,输出该年份

该月的天数。请在【】内填入正确内容。 #include ”stdio.h” main() {

int year, month, days, leap;

printf(”please input both year and month:”); scanf(”M/-”,&year,&month); switch (【1】) { case 1: case 3: case 5; case 7: case 8:

搜索更多关于: C语言基础练习题(含答案) 的文档
C语言基础练习题(含答案).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c4a23t6h0t82b61y989mf_9.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top