抄寫例題作業1

2022-09-12 16:45:22 字數 4837 閱讀 5466

定義結構體變數a並初始化

printf("

no.:%d\nname:%s\n***:%c\naddress:%s\n

",a.num,a.name,a.***,a.addr);

return0;

}

no.:10101

name:li lin

***:m

address:beijing road

--------------------------------process exited after

0.09505 seconds with return value 0

請按任意鍵繼續. . .

9.2

#include"

stdio.h

"int

main()

student1,student2;

//定義兩個結構體變數 student1,student2

scanf("

%d%s%f

",&student1.num,student1.name,&student1.score); //

輸入學生1的資料

scanf("

%d%s%f

",&student2.num,student2.name,&student2.score); //

輸入學生2的資料

printf("

the higher score is:\n");

if(student1.score>student2.score)

printf(

"%d %s %6.2f\n

",student1.num,student1.name,student1.score);

else

if(student1.score

printf(

"%d %s %6.2f\n

",student2.num,student2.name,student2.score);

else

return0;

}

01 li 66

02 ni 99

the higher score is:

2 ni 99.00

--------------------------------process exited after

12.45 seconds with return value 0

請按任意鍵繼續. . .

9.3

#include"

string.h

"#include

"stdio.h

"struct person //

宣告結構體型別 struct person

leader[3]=; //

定義結構體陣列並初始化

intmain()

printf(

"\nresult:\n");

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

printf(

"%5s:%d\n

",leader[i].name,leader[i].count);

return0;

}

li

liyi

yiyi

zizi

yiyi

liresult:

li:3yi:

5zi:

2--------------------------------process exited after

28.38 seconds with return value 0

請按任意鍵繼續. . .

9.4

#include"

stdio.h

"struct student //

宣告結構體型別 struct student

;

intmain()

,,,,};

struct

student temp;

const

int n=5

;

inti,j,k;

printf(

"the order is:\n");

for(i=0;i1;i++)

for(i=0;i)

printf(

"%6d %8s %6.2f

",stu[i].num,stu[i].name,stu[i].score);

printf("\n

");return0;

}

the order is: 

10108 ling 73.50

10103 wang 98.50

10106 li 86.00

10101 zhang 78.00

10110 sun 100.00

--------------------------------process exited after

0.101 seconds with return value 0

請按任意鍵繼續. . .

9.5

#include"

stdio.h

"#include

"string.h

"int

main()

;

struct

student stu_1;

struct student *p;

p=&stu_1;

stu_1.num=10101

; strcpy(stu_1.name,

"li lin");

stu_1.***='m'

; stu_1.score=89.5

; printf(

"no.:%1d\nname:%s\n***:%c\nscore:5.1%f\n

",stu_1.num,stu_1.name,stu_1.***,stu_1.score);

printf(

"\nno.:%1d\nname:%s\n***:%c\nscore:5.1%f\n

",(*p).num,(*p).name,stu_1.***,(*p).score);

return0;

}

no.:10101

name:li lin

***:m

score:

5.189.500000

no.:

10101

name:li lin

***:m

score:

5.189.500000

--------------------------------process exited after

0.17 seconds with return value 0

請按任意鍵繼續. . .

9.6

#include"

stdio.h

"struct

student

;struct student stu[3]=,,};

intmain()

no.    name                *** age

10101 li lin m 18

10102 wang ya m 19

10104 lu fei f 20

--------------------------------process exited after

0.1014 seconds with return value 0

請按任意鍵繼續. . .

9.7

#include #define n 3  

struct

student

; int

main()

void input(struct

student stu) }

struct student max(struct

student stu)

void print(struct

student stud)

請輸入各學生的資訊:學號、姓名、三門學科的成績:

01 yaya 11

1213

02 wangya 14

1516

03 yy 17

1819

成績最高的學生是:

學號:3

姓名:yy

三門課成績:

17.0, 18.0, 19.0平均成績: 0.00

--------------------------------process exited after

53.69 seconds with return value 0

請按任意鍵繼續. . .

總結:自己打了這麼多的例題,發現這個結構體的內容差不多是一樣的,只要掌握的一種,這類題做起來就很簡單。

抄寫例題作業1

例 9.1 includestruct student stu intmain 學號 1001 姓名 張三 性別 男 位址 哈爾濱 process exited after 0.01108 seconds with return value 0 請按任意鍵繼續.例 9.2 include inclu...

抄寫例題作業

9.1 includeint main a printf no.d n name s n c n addr s n a.num,a.name,a.a.addr no.10101 name li lin m address 123beijing road process exited after 0....

第四周作業的抄寫部分

有一種細菌分為a b兩個亞種,它們的外在特徵幾乎完全相同,僅僅在繁殖能力上有顯著差別,a亞種繁殖能力非常強,b亞種的繁殖能力很弱。在一次為時乙個小時的細菌繁殖實驗中,實驗員由 於疏忽把細菌培養皿搞亂了,請你編寫乙個程式,根據實驗結果,把兩個亞種的培養皿重新分成兩組。include using nam...