⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 练习(一).txt

📁 谭浩强的C语言题集
💻 TXT
📖 第 1 页 / 共 4 页
字号:
       1
   (B) 1
       1
       1
       1
   (C) 0
       1
       0
       1
   (D) 0
       1
       0
       0
二、填空题
35、当a=3,b=2,c=1时,表达式f=a>b>c的值是________。
36、当a=5,b=4,c=2时,表达式a>b!=c的值是________。
37、以下程序的运行结果是________。
	#include<stdio.h>
	void main()
	{
		int x=1,y,z;
		x*=3+2;
		printf("%d\t",x);
		x*=y=z=5;
		printf("%d\t",x);
		x=y==z;
		printf("%d\n",x);
	}
38、在C语言中,表示逻辑“真”值用________。
39、设y为int型变量,请写出描述“y是奇数”的表达式是________。
40、C语言提供的三种逻辑运算符是________、________、________。
41、设x,y,z均为int型变量,请写出描述“x或y中有一个小于z”的表达式________。
42、设x,y,z均为int型变量,请写出描述“x,y和z中有两个为负数”的表达式________。
43、已知A=7.5,B=2,C=3.6,表达式A>B&&C>A||A<B&&!C>B的值是________。
44、若a=6,b=4,c=2,则表达式!(a-b)+c-1&&b+c/2的值是________。
45、若a=2,b=4,则表达式!(x=a)||(y=b)&&0的值是________。
46、若a=1,b=4,c=3,则表达式!(a<b)||!c&&1的值是________。
47、若a=6,b=4,c=3,则表达式a&&b+c||b-c的值是________。
48、若a=5,b=2,c=1,则表达式a-b<c||b==c的值是________。
49、设a=3,b=4,c=5,则表达式a||b+c&&b==c的值是________。
50、条件“2<x<3或x<-10”的C语言表达式是________。
51、当m=2,n=1,a=1,b=2,c=3时,执行完d=(m=a!=b)&&(n=b>c)后,n的值为________,m的值为________。
52、以下程序的运行结果是________。
	void main()
	{
		int x,y,z;
		x=1; y=2; z=3;
		x=y--<=x||x+y!=z;
		printf("%d,%d",x,y);
	}
53、以下程序的运行结果是________。
	void main()
	{
		int a1,a2,b1,b2;
		int i=5,j=7,k=0;
		a1=!k;
		a2=i!=j;
		printf("a1=%d\ta2=%d\n",a1,a2);
		b1=k&&j;
		b2=k||j;
		printf("b1=%d\tb2=%d\n",b1,b2);
	}
54、以下程序的运行结果是________。
	void main()
	{
		int x,y,z;
		x=1;y\1;z=0;
		x=x||y&&z;
		printf("%d,%d",x,x&&!y||z);
	}
55、有int x,y,z; 且x=3,y=-4,z=5,则表达式(x&&y)==(x||z)的值为________。
56、有int x,y,z; 且x=3,y=-4,z=5,则以下表达式的值为________。
	!(x>y)+(y!=z)||(x+y)&&(y-z)
57、有int x,y,z; 且x=3,y=-4,z=5,则表达式x++-y+(++z)的值为________。
58、有int a=3,b=4,c=5;,则表达式a||b+c&&b==c的值为________。
59、有int a=3,b=4,c=5,x,y;,则以下表达式的值为________。
	!(x=a)&&(y=b)&&0
60、有int a=3,b=4,c=5;,则以下表达式的值为________。
	!(a+b)+c-1&&b+c/2
61、若运行时输入:16〈回车〉,则以下程序的运行结果是________。
	#include <stdio.h>
	void main()
	{
		int year;
		printf("Input your year: ");
		scanf("%d",&year)
		if(year>=18)
			printf("you $ 4.5 yuan/xiaoshi");
		else
			printf("your $ 3.0 yuan/xiaoshi");
	}
62、若运行时输入:2〈回车〉,则以下程序的运行结果是________。
	#include <stdio.h>
	void main()
	{
		char Class;
		printf("Enter 1 for 1st class post or 2 for 2nd pos");
		scanf("%c",&Class);
		if(Class=='1')
			printf("1st class postage is 19p");
		else
			printf("2nd class postage is 14p");
	}
63、若运行时输入:4.4〈回车〉,则以下程序的运行结果是________。
	#include <stdio.h>
	void main()
	{
		float CostPrice,SellingPrice;
		printf("Enter cost Price $ : ");
		scanf("%f",&CostPrice);
		if(CostPrice>=5)
		{
			SellingPrice=costPrice+CostPrice*0.25;
			printf("Selling Price(0.25) $ %6.2f",SellingPrice);
		}
		else
		{
			SellingPrice=CostPrice+CostPrice*0.30;
			printf("Selling Price(0.30) $ %6.2f",SellingPrice);
		}
64、以下程序的运行结果是________。
	void main()
	{
		if(2*2==5<2*2==4)
			printf("T");
		else
			printf("F");
	}
65、请阅读以下程序:
	void main()
	{
		int t,h,m;
		scanf("%d",&t);
		h=(t/100)%12;
		if(h==0) h=12;
		printf("%d:",h);
		m=t%100;
		if(m<10) printf("0");
		printf("%d",m);
		if(t<1200||t==2400)
			printf(" AM");
		else printf(" PM");
	}
66、以下程序实现:输入圆的半径r和运算标志m,按照运算标志进行指定计算。请在________内填入正确内容。
	标志		运算
	 a	       面  积
	 c	       周  长
	 b	     二者均计算

	#define pi 3.14159
	void main()
	{
		char m;
		float r,c,a;
		printf("input mark a c or b&& r\n");
		scanf("%c %f",&m,&r);
		if(________)
		{
			a=pi*r*r;
			printf("area is %f",a);
		}
		if(________)
		{
			c=2*pi*r;
			printf("circle is %f",a);
		}
		if(________)
		{
			a=pi*r*r;
			c=2*pi*r;
			printf("area && circle are %f %f",a,c);
		}
	}
67、若运行时输入:5999〈回车〉,则以下程序的运行结果(保留小数点后一位)是________。
	void main()
	{
		int x;
		float y;
		scanf("%d",&x);
		if(x>=0 && x<=2999) y=18+0.12*x;
		if(x>=3000 && x<=5999) y=36+0.6*x;
		if(x>=6000 && x<=10000) y=54+0.3*x;
		printf("%6.1f",y);
	}
68、以下程序实现输出x,y,z三个数中的最大者。请在________内填入正确内容。
	void main()
	{
		int x=4,y=6,z=7;
		int ________;
		if(________) u=x;
		else u=y;
		if(________) v=u;
		else v=z;
		printf("v=%d",v);
	}
69、以下程序实现:输入三个整数,按从小到大的顺序进行输出。请在________内填入正确内容。
	void main()
	{
		int x,y,z,c;
		scanf("%d %d %d",&x,&y,&z);
		if(________) { c=y; y=z; z=c;}
		if(________) { c=x; x=z; z=c;}
		if(________) { c=x; x=y; y=c;}
		printf("%d,%d,%d",x,y,z);
	}
70、以下程序对输入的两个整数,按从大到小顺序输出。请在________内填入正确内容。
	void main()
	{
		int x,y,z;
		scanf("%d,%d",&x,&y);
		if(________) { z=x;________;}
		printf("%d,%d",x,y);
	}
71、以下程序对输入的一个小写字母,将字母循环后移5个位置后输出,如'a'变成'f','w'变成'b'。请在________内填入正确内容。
	#include "stdio.h"
	void main()
	{
		char c;
		c=getchar();
		if(c>='a' && c<='u') ________;
		else if(c>='v' && c<='z') ________;
		putchar(c);
	}
72、输入一个字符,如果它是一个大写字母,则把它变成小写字母;如果它是一个小写字母,则把它变成大写字母;其它字符不变。请在________内填入正确内容。
	void main()
	{
		char ch;
		scanf("%c",&ch);
		if(________) ch=ch+32;
		else if(ch>='a'&&ch<='z') ________;
		printf("%c",ch);
	}
73、以下程序的运行结果是________。
	void main()
	{
		int a,b,c;
		int s,w,t;
		s=w=t=0;
		a=-1;b=3;c=3;
		if(c>0) s=a+b;
		if(a<=0)
		{
			if(b>0)
				if(c<=0) w=a-b;
		}
		else if(c>0) w=a-b;
		else t=c;
		printf("%d %d %d",s,w,t);
	}
74、以下程序的运行结果是________。
	void main()
	{
		int a,b,c,d,x;
		a=c=0;
		b=1;
		d=20;
		if(a) d=d-10;
		else if(!b)
			if(!c) x=15;
			else x=25;
		printf("%d\n",d);
	}
75、以下程序的运行结果是________。
	#include <stdio.h>
	void main()
	{
		int x,y=1,z;
		if(y!=0) x=5;
		printf("\t%d\n",x);
		if(y==0) x=4;
		else x=5;
		printf("\t%d\n",x);
		x=1;
		if(y<0)
			if(Y>0) x=4;
			else x=5;
		printf("\t%d\n",x);
76、以下程序的输出结果是________。
	#indlude <stdio.h>
	void main()
	{
		int x,y=-2,x=0;
		if((z=y)<0) x=4;
		else if(y\\0) x=5;
		else x=6;
		printf("\t%d\t%d\n",x,z);
		if(z=(y==)))
		x=5;
		x=4;
		printf("\t%d\t%d\n",x,z);
		if(x=z=y) x=4;
		printf("\t%d\t%d\n",x,z);
	}
77、请阅读下面的程序:
	void main()
	{
		int s,t,a,b;
		scanf("%d,%d",&a,&b);
		s=1;
		t=1;
		if(a>0) s=s+1;
		if(a>b) t=s+t;
		else if(a==b) t=5;
		else t=2*s;
		printf("s=%d,t=%d",s,t);
	}
    为了使输出结果t=4,输入量a和b应满足的条件是________。
78、请阅读下面程序:
	void main()
	{
		int s,t,a,b;
		scanf("%d,%d",&a,&b);
		s=1;
		t=1;
		if(a>0) s=s+1;
		if(a>b) t=s+t;
		else if(a==b) t=5;
		else t=2*s;
		printf("s=%d,t=%d",s,t);
	}
    为了使输出结果s=1,t=5,输入量a和b应满足的条件是________。
79、下面程序根据以下函数关系,对输入的每个x值,计算出y值。请在________内填入正确内容。
	┏━━━━┯━━━┓
	┃   x    │  y   ┃
        ┠────┼───┨
	┃2<x<=10 │x(x+2)┃
        ┠────┼───┨
	┃-1<x<=2 │2x    ┃
        ┠────┼───┨
	┃x<=-1   │x-1   ┃
        ┗━━━━┷━━━┛

	void main()
	{
		int x,y;
		scanf("%d",&x);
		if(________) y=x*(x+2);
		else if(________) y=2*x;
		else if(x<=-1) y=x-1;
		else ________;
		if(y!=-1) printf("%d",y);
		else printf("error");
	}
80、下面程序根据以下函数关系,对输入的每个x值,计算出相应的y值。请在________内填入正确内容。
	┏━━━━━┯━━━━━━━┓
	┃    x     │     y        ┃
        ┠─────┼───────┨
	┃x=a或x=-a │0             ┃
        ┠─────┼───────┨
	┃-a<x<a    │sqrt(a*a-x*x) ┃
        ┠─────┼───────┨
	┃x<-a或x>a │x             ┃
        ┗━━━━━┷━━━━━━━┛

	#include "math.h"
	void main()
	{
		int x,a;
		float y;
		scanf("%d %d",&x,&a);
		if(________) y=0;
		else if(________) y=sqrt(a*a-x*x);
		else y=x;
		printf("%f",y);
	}
81、以下程序的功能是计算一元二次方程ax*x+bx+c=0的根。请在________内填入正确内容。
	#include "math.h"
	void main()
	{
		float a,b,c,t,disc,twoa,term1,term2;
		printf("enter a,b,c:");
		scanf("%f%f%f",&a,&b,&c);
		if(________)
			if(________) printf("no answer due to input error\n");
			else printf("the single root is %f\n",-c/b);
		else
		{
			disc=b8b-4*a*c;
			twoa=2*a;
			term1=-b/twoa;
			t=abs(disc);
			term2=sqrt(t)/twoa;
			if(________)
				printf("complex root\n real part=%f imag part=%f\n",term1,term2);
			else
				printf("real roots\n root1=%f root2=%f\n",term1+term2,term1-term2);
		}
	}
82、以下程序根据输入的三角形的三边判断是否能组成三角形,若可以则输出它的面积和三角形的类型。请在________内填入正确内容。
	#include "math.h"
	main()
	{
		float a,b,c;
		float s,area;
		scanf("%f %f %f",&a,&b,&c);
		if(________)
		{
			s=(a+b+c)/2;
			area=sqrt(s*(s-a)*(s-b)*(s-c));
			printf("%f",area);
			if(________)
				printf("等边三角形");
			else if(________)
				printf("等腰三角形");
			else if((a*a+b*b==c*c)||(a*a+c*c==b*b)||(b*b+c*c==a*a))
				printf("直角三角形");
			else printf("一般三角形");
		}
		else printf("不能组成三角形");
	}
83、某邮局对邮寄包裹有如下规定:若包裹的长度在一尺寸超过1或重量超过30千克,不予邮寄;对可以邮寄的包裹每件收手续费0.2元,再加上根据下表按重量wei计算的邮资:
	┏━━━━━━┯━━━━━━━┓
	┃重量(千克)│收费标准(元)┃
        ┠──────┼───────┨
	┃   wei<10   │    0.80      ┃
        ┠──────┼───────┨
	┃10<wei<=20  │    0.75      ┃
        ┠──────┼───────┨
	┃20<wei<=30  │    0.70      ┃
        ┗━━━━━━┷━━━━━━━┛
    请在程序的________内填入正确内容。
	void main()
	{
		float len,wei,hei,wid,mon,r;
		scanf("%f %f %f %f",&len,&wid,&hei,&wei);
		if(len>1||wid>1||hei>1||wei>30) ________;
		else if(wei<10) r=0.8;
		else if(wei<=20) r=0.75;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -