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

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

来源:网络收集 时间:2021-09-24 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

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]);

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说公务员考试华中科技大学标准C语言程序设计及应用习题答案(3)在线全文阅读。

华中科技大学标准C语言程序设计及应用习题答案(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/gongwuyuan/1247891.html(转载请注明文章来源)

相关推荐:

Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: