教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 教育文库 >

华中科技大学标准C语言程序设计及应用习题答案(2)

来源:网络收集 时间:2026-09-14
导读: main:x=5,y=1,n=11 func:x=8,y=31,n=21 1.D 2.D 3.C 4.6 5.CDABC 6.(1)j+=2 (2)a[i]a[j] 7.(1)s[i++]!='\0' (2)s[i-1] 8.D 9.B 10.6(同题4) 11.s[i]='0's[i]='9' 12. (1)'\0' (2)str1[i]-str2[i] 5.1 #includestdio

main:x=5,y=1,n=11

func:x=8,y=31,n=21

1.D

2.D

3.C

4.6

5.CDABC

6.(1)j+=2

(2)a[i]<a[j]

7.(1)s[i++]!='\0'

(2)s[i-1]

8.D

9.B

10.6(同题4)

11.s[i]>='0'&&s[i]<='9'

12. (1)'\0' (2)str1[i]-str2[i]

5.1

#include<stdio.h>

int fun();

int fun()

{

int a[3][3],sum; 第五章

int i,j;

sum=0;/*error*/

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

scanf("%d",&a[i][j]);/*error*/

}

for(i=0;i<3;i++)

sum=sum+a[i][i];

printf("sum=%d\n",sum);

}

void main()

{

fun();

}

5.2

#include <stdio.h>

void main( void )

{

float Num[10];

float Input,GetNum[11];

int i,j;

float a=6;

for(i=0; i<10; i++)

{

Num[i]=a;

a=a+7.5;

}

Loop1: printf("Please input a Number(0-80) Input=");

scanf("%f",&Input);

if((Input<0)||(Input>70)==1)

goto Loop1;

for(i=0; i<10; i++ )

{

if(Input<Num[i])

goto Loop2;

}

Loop2: for(j=0; j<i; j++ )

GetNum[j]=Num[j];

GetNum[j]=Input;

for(j=i; j<=10; j++,i++)

GetNum[j+1]=Num[i];

for(j=0; j<11; j++ )

printf("%3.3f ",GetNum[j]);

}

5.3

#include "stdio.h"

#include "stdlib.h"

main()

{

int a1,a2,a3,a4,a5,a6,a7,a8,a9;

int a[3];

int i;

for(;;)

{

for (i=0;i<3;i++)

{

a[i]=rand()%3;

}

while((a[0]!=a[1]) && (a[0]!=a[2]) && (a[1]!=a[2]))/*get three different numbers 0,1,2*/

{

a1=a[0]+1;/*divide 1~9 into three groups,a1~a3,a4~a6,a7~a9*/

a2=a[1]+1;

a3=a[2]+1;

a4=a1+3;

a5=a2+3;

a6=a3+3;

a7=a1+6;

a8=a2+6;

a9=a3+6;

/* make sure that each line and each row is made up with three members in different group.*/

/* such as: a9 a1 a5

a2 a6 a7

a4 a8 a3 */

if(((a1+a5+a9) == (a2+a6+a7)) && ((a1+a5+a9) == (a3+a4+a8))

&& ((a1+a6+a8) == (a5+a7+a3)) && ((a1+a5+a9) == (a2+a4+a9))) {

printf("%d %d %d\n%d %d %d\n%d %d %d\n",a9,a1,a5,a2,a6,a7,a4,a8,a3); return;

}

}

}

}

5.4

#include <stdio.h>

void main(void)

{

char input1[100],input2[100],input3[100];

int i,Eng=0,eng=0,num=0,blank=0,other=0;

printf("Input 3 rows of character,each row don't exceed 80 characters:\n");

gets(input1);

printf("The second row:\n");

gets(input2);

printf("The third row:\n");

gets(input3);

/*test the first row*/

for(i=0; i<100; i++)

{

if(input1[i]=='\0')

goto Loop1;

else if(('A'<=input1[i])&&(input1[i]<='Z')==1)

Eng++;

else if(('a'<=input1[i])&&(input1[i]<='z')==1)

eng++;

else if(('0'<=input1[i])&&(input1[i]<='9')==1)

num++;

else if(input1[i]==32)

blank++;

else other++;

}

/*test the second row*/

Loop1: for(i=0; i<100; i++)

{

if(input2[i]=='\0')

goto Loop2;

else if(('A'<=input2[i])&&(input2[i]<='Z')==1)

Eng++;

else if(('a'<=input2[i])&&(input2[i]<='z')==1)

eng++;

else if(('0'<=input2[i])&&(input2[i]<='9')==1)

num++;

else if(input2[i]==32)

blank++;

else other++;

}

/*test the third row*/

Loop2: for(i=0; i<100; i++)

{

if(input3[i]=='\0')

goto Loop3;

else if(('A'<=input3[i])&&(input3[i]<='Z')==1)

Eng++;

else if(('a'<=input3[i])&&(input3[i]<='z')==1)

eng++;

else if(('0'<=input3[i])&&(input3[i]<='9')==1)

num++;

else if(input3[i]==32)

blank++;

else other++;

}

Loop3: printf("Upper english character:%d\nLower english character:%d\nNumber:%d\nBlank:%d\nOther characters:%d\n",Eng,eng,num,blank,other); }

5.5

#include <stdio.h>

void main(void)

char str1[80],str2[40];

int i,j,k;

/*Input two string*/

printf("Please input the first string\n str1=");

gets(str1);

printf("Please input the second string\n str2=");

gets(str2);

/*Get the end of str1*/

for(i=0; i<80; i++)

{

if(str1[i]=='\0')

break;

}

/*Copy str2 to str1*/

for(j=i,k=0; str2[k]!='\0';k++,j++)

str1[j]=str2[k];

str1[i+k]='\0';

puts(str1);

}

5.6

#include <stdio.h>

struct student

{char name[20];

int score;

}stu[5],stu1;

void main(void)

{ int i,j;

printf("Input student's score and name(5),seperate using the character of ',' :\n");

for(i=0; i<5; i++)

scanf("%d,%s",&stu[i].score,&stu[i].name);

/*sorting*/

for(i=0; i<5; i++)

for(j=0; j<4-i; j++)

if(stu[j].score>stu[j+1].score)

{stu1=stu[j];stu[j]=stu[j+1];stu[j+1]=stu1;}

printf("After sotred,score and name:\n");

for(i=0; i<5; i++)

printf("%d,%s\n",stu[i].score,stu[i].name);

}

5.7

#include<stdio.h>

main()

{ int a[3][3],i,j,m,n,o,p;

printf("Please input a 3*3 shuzu:\n");

for (i=0;i& …… 此处隐藏:3035字,全部文档内容请下载后查看。喜欢就下载吧 ……

华中科技大学标准C语言程序设计及应用习题答案(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/280875.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)