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

C习题集 (4)

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

if(l!=i) {

temp=a[i]; a[i]=a[l]; a[l]=temp; } } }

void main()

{ char *name[4],

ch[4][15]={ ”morning”,”afternoon”,”night”,”evening” }; int k;

for(k=0;k<4;k++) name[k]=ch[k]; sort(name,4); for(k=0;k<4;k++)

printf(”%s\\n”,name[k]); }

19. #include \

void pline(char *a,char c,int l,int n) 输出结果: { int i; for(i=1;i

void main() { char a[80];

int i; void (*pf)(char*,char,int,int); pf=pline;

for(i=1;i<5;i++) {

(*pf)(a,'$',5-i,2*i-1); puts(a); } }

20. #include \

int binary(int x,int a[],int n) 输出结果: { int low=0,high=n-1,mid; while(low<=high) { mid=(low+high)/2;

if(x>a[mid]) high=mid-1; else if(x

return(-1); }

15

void main( )

{ static int a[]={4,0,2,3,1}; int i,t,j; for(i=1;i<5;i++) { t=a[i]; j=i-1;

while(j>=0&&t>a[j]) { a[j+1]=a[j]; j--; }

a[j+1]=t; }

printf (\ }

21. #include

#include void main( )

{ double f(double,int);

printf(\ }

double f(double x,int n) { double t;

if(n==1) t=x; else {

if(n/2*2==n)t=x*f(x,n/2); else t=x*pow(f(x,n/2),2.0); }

return t; }

22. #include

double x,u,v double t(double a,double(*f)(double)) { return(*f)(a*a); } double f(double x) { return 2.0*x; } double g(double x) { return 2.0+x; } void main()

{ x=4.0;u=t(x,f);v=t(x,g);

printf(\ }

23. #include

16

输出结果: 输出结果: void main()

{ static struct s1{ char c[4],*s; }; s1={\

static struct s2{char *cp; struct s1 ss1;} s2={\

printf(\输出结果: printf(\ printf(\ printf (\ }

24. #include

struct s1{ char *s; int i; struct s1 *s1p; }; void main()

{ static struct s1 a[]={{\ int i;

for(i=0;i<2;i++) 输出结果: { printf(\ printf(\ }

25. #include void main()

{ FILE *fp; int i;

char s1[80],s[]=\ fp=fopen(\

fwrite(s,i,1,fp); rewind(fp); fread(s1,i,l,fp); printf(\ printf(\

fseek(fp,10,1); 输出结果: printf(\ fseek(fp,1,1); printf(\ fclose(fp); }

17

4 程序填空题

根据读下列各题题意填空,写入在程序中的划线处。 1. 输入2个整数,输出它们的最小公倍数和最大公约数。 #include void main( )

{ int m,n,gbs,gys;

scanf( ⑴ );

for(gbs=m; ⑵ ; gbs=gbs+m); gys= ⑶

⑷ }

2. 输入N个实数,输出其中的最大值、最小值。

#include void main()

{ float no1,nmax,nmin; ⑴ scanf(\ nmax=no1; ⑵ for(i=2;i<=n;i++) {

scanf(\⑶ );

if(nox>nmax) nmax=nox; ⑷ }

printf(\ }

3. 输入20个数,输出它们的平均值,输出与平均值之差的绝对值为最小的数组元素。 #include ⑴ void main()

{ float a[20],pjz=0,s,t; int i,k; ⑵

for(i=0;i<20;i++) pjz+=a[i]; ⑶ s=fabs(a[0]-pjz); for(i=1;i<20;i++)

if(fabs(a[i]-pjz)

s=fabs(a[i]-pjz); t=a[i]; }

⑷ }

18

4. 输入若干个字符,分别统计数字字符的个数、英文字母的个数,当输入换行符时输 出统计结果,运行结束。

#include void main()

{ char ch; ⑴

while(( ⑵ )!='\\n') { if(ch>='0'&&ch<='9') s1++;

if(ch>='a'&&ch<='z' ⑶ ) s2++; }

⑷ }

5. 输入m,求n使 n!<=m<=(n+1)!,例如输入726,应输出n=6。 ⑴ void main()

{ int ⑵ ;

scanf( ⑶ ); for(n=2;jc<=m;n++) jc=jc*n;

printf(”n=%d\\n”, ⑷ ); }

222

6. 下列程序计算并输出方程 X+Y+Z=1989 的所有整数解。 #include void main()

{ ⑴

for(i1=-45;i1<=45;i1++)

for( ⑵ ) for(i3=-45;i3<=45;i3++)

if( ⑶ )

printf( ⑷ ,i1,i2,i3); }

7. 下列程序求n(n的值由运行时确定)个正整数的最小公倍数。 #include #include void main()

{ int *p,i,n,gbs;

⑴ p= ⑵ ; for(i=0;i

if( ⑶ ) { gbs+=*p; ⑷

19

搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新幼儿教育C习题集 (4)全文阅读和word下载服务。

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