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

2021-09-24 12:32

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<=2;i++)

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

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

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

{ m=(a[i][0]>a[i][1])? a[i][0]:a[i][1];

n=(m>a[i][2])? m: a[i][2];

}

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

{ o=(a[0][j]<a[1][j])? a[0][j]:a[1][j];

p=(o<a[2][j])? o: a[2][j];

}

if (n==p)

printf("Andian is %d\\n",p);

else

printf("There is no andian.\\n");

}

5.8

#include <stdio.h>

void main(void)

{ int a[4][3],b[3][4],i,j;

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

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

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

}

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

{

printf("\n");

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

printf("%5d ",a[i][j]);

}

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

{

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

b[j][i]=a[i][j];

}

printf("\n");

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

{

printf("\n");

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

printf("%5d ",b[i][j]);

华中科技大学标准C语言程序设计及应用习题答案(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:工程资金使用计划

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: