2025-03-20
This commit is contained in:
		
							parent
							
								
									72b6014ddf
								
							
						
					
					
						commit
						2f7f806aab
					
				| @ -16,13 +16,18 @@ void output(student stuList[5]){ | ||||
|                                 stuList[i].socre[1], stuList[i].socre[2]); | ||||
|     } | ||||
| } | ||||
| int main(){ | ||||
|     student stuList[5];//定义了一个结构体数组里面可以容纳5个结构体变量
 | ||||
| 
 | ||||
| void input(student stuList[5]){ | ||||
|     int i; | ||||
|     for(i=0;i<5;i++){ | ||||
|         scanf("%d %s %f %f %f", &stuList[i].num, stuList[i].name, &stuList[i].socre[0],  | ||||
|                                 &stuList[i].socre[1], &stuList[i].socre[2]); | ||||
|     } | ||||
| } | ||||
| int main(){ | ||||
|     student stuList[5];//定义了一个结构体数组里面可以容纳5个结构体变量
 | ||||
| 
 | ||||
|     input(stuList); | ||||
|     output(stuList); | ||||
|     return 0; | ||||
| } | ||||
| @ -971,6 +971,42 @@ int main(){ | ||||
| 
 | ||||
|  | ||||
| 
 | ||||
| ```c | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| typedef struct student{ | ||||
|     int num; | ||||
|     char name[20]; | ||||
|     float socre[3]; | ||||
| }student; | ||||
| //student 作为一个类型 | ||||
| //如果不写typedef则结构体类型为 struct student | ||||
| 
 | ||||
| void output(student stuList[5]){ | ||||
|     int i; | ||||
| 
 | ||||
|     for(i=0;i<5;i++){ | ||||
|         printf("%d\t%s\t%f\t%f\t%f\n", stuList[i].num, stuList[i].name, stuList[i].socre[0],  | ||||
|                                 stuList[i].socre[1], stuList[i].socre[2]); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void input(student stuList[5]){ | ||||
|     int i; | ||||
|     for(i=0;i<5;i++){ | ||||
|         scanf("%d %s %f %f %f", &stuList[i].num, stuList[i].name, &stuList[i].socre[0],  | ||||
|                                 &stuList[i].socre[1], &stuList[i].socre[2]); | ||||
|     } | ||||
| } | ||||
| int main(){ | ||||
|     student stuList[5];//定义了一个结构体数组里面可以容纳5个结构体变量 | ||||
| 
 | ||||
|     input(stuList); | ||||
|     output(stuList); | ||||
|     return 0; | ||||
| } | ||||
| ``` | ||||
| 
 | ||||
| ### 结构体-3 | ||||
| 
 | ||||
|  | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user