结构体
来源:互联网 发布:java开发笔试题及答案 编辑:程序博客网 时间:2024/06/05 10:50
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <string.h>//结构体struct Person{ char name[20]; int count;}leader[3] = { "Li", 0, "Zhang", 0, "Sun", 0 };int main1(){ int i, j; char leader_name[20]; for (i = 0; i <= 10; i++) { scanf("%s", leader_name); for (int j = 0; j < 3; j++) if (strcmp(leader_name, leader[j].name) == 0)//如果输入名字一直,相应count+1 leader[j].count++; } printf("\nResult:\n\n"); for (i = 0; i < 3; i++) printf("%5s:%d\n", leader[i].name, leader[i].count);}struct Student{ int num; char name[20]; float score;};int main2(){ struct Student stu[5] = { { 11001, "Zhang", 80 }, { 11003, "Wang", 98.5 }, { 11005, "li", 86 }, { 11008, "Ling", 73.5 }, { 11002, "Sun", 100 } }; struct Student temp; const int n = 5; int i, j, k; printf("the order is:\n"); for ( i = 0; i < n-1; i++) { k = i; for (j = i + 1; j < n; j++) if (stu[j].score>stu[k].score) k = j; temp = stu[i]; stu[i] = stu[k]; stu[k] = temp; } for ( i = 0; i < n; i++) printf("%6d,%6s,%6.2f\n", stu[i].num, stu[i].name, stu[i].score);}struct Student_1{ int num; char name[20]; char sex; float score;};int main3(){ struct Student_1 stu1; struct Student_1 *p; int i; p = &stu1; stu1.num = 10101; strcpy(stu1.name, "Li Ming"); stu1.sex = 'M'; stu1.score = 89.5; printf("%5d,%10s,%2c,%6.2f\n", stu1.num, stu1.name, stu1.sex, stu1.score); printf("%5d,%10s,%2c,%6.2f\n", p->num, p->name, p->sex, p->score);}struct Student stu[5] = { { 11001, "Zhang", 80 }, { 11003, "Wang", 98.5 }, { 11005, "li", 86 }, { 11008, "Ling", 73.5 }, { 11002, "Sun", 100 } };//定义结构体数组并初始化int main(){ struct Student *p;//定义指向结构体变量的指针变量 for (p = stu; p < stu + 5; p++) printf("%5d %-20s% 5.2f\n", p->num, p->name, p->score); system("pause"); return 0;}
阅读全文
0 0
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体
- 结构体,,,,
- 结构体
- 结构体
- 阿里笔试(二)
- JAVA可视化插件的使用
- 抽取数据库查询抽取和分页抽取和数据回显问题
- Android攻城狮的第二门课(第1季)第2章 使用ListView显示信息列表
- 【23种设计模式】行为型模式 > 观察者模式
- 结构体
- java面向对象/多态
- SpringMVC框架中文乱码解决方案
- windows server 2008搭建NTP时间服务器和客户端
- GPUImage学习日记(1)
- 贪心、动态规划之删数问题2072
- F12 console的用法,以及如何debug程序?
- 计蒜客-三值排序(贪心)
- 内联函数与宏定义