输入:16300430,输出:huhai 输入:huhai,输出:16300430 大一的课堂练习,我写了两个还是有错误,想来看看大神的操作
6条回答 默认 最新
- 往事如风,闲云野鹤 2021-05-31 08:50关注
#include "stdio.h" #include<string.h> #define N 2 typedef struct student{ int stuno; char stuname[10]; }student; int main(int argc, char* argv[]) { int num; int i=0; int stuno; char stuname[10]; student stu[N]={{1001,"zhangsan"},{1002,"lisi"}}; printf("请输入您想查询的方式:1、根据学号查询 2、根据姓名查询"); scanf("%d",&num); if(num==1){ printf("请输入学号:"); scanf("%d",&stuno); for(i=0;i<N;i++){ if(stu[i].stuno==stuno){ printf("%s\n",stu[i].stuname); break; } } }else if(num==2){ printf("请输入姓名:"); scanf("%s",&stuname); for(i=0;i<N;i++){ if(strcmp(stu[i].stuname, stuname) == 0){ printf("%d\n",stu[i].stuno); break; } } if(i==N){ printf("姓名为%s的学生不存在",stuname); } }else{ printf("只能输入1或者2"); } return 0; }
代码如上,万望采纳。
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 3无用
悬赏问题
- ¥20 西门子S7-Graph,S7-300,梯形图
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效
- ¥15 悬赏!微信开发者工具报错,求帮改