怎样用C语言定义一个二维数组存放班级10位同学姓名,输入一个姓名,要求查询该学生是否属于该班级
展开全部
#include<stdio.h>
#include<string.h>
main()
{ char a[10][10]={"Tom","Jerry","Mary","Angel","Baby","Mic","Tem","Blue","Britney","Gagy"};
char b[10];
int i,j;
while(1){
scanf("%s",&b);
getchar();
j=0;
for(i=0;i<10;i++)
if(strcmp(a[i],b)==0) j=1;
if(j) printf("YES\n\n");
else printf("NO\n\n");
}
}
如图所示,望采纳。。。。。。
更多追问追答
追问
为啥要用while(1)
追答
为了可以反复输入,反复判断
展开全部
#include "stdio.h"
#include <string.h>
int main(int argc,char *argv[]){
char stun[10][20]={"Zhangsan","Lisi","Wangwu","Zhaoliu","Weiqi","Maba","Houjiu","Jishi"},t[20],i;
printf("Please enter a name to find:\n");
scanf("%19s",t);
for(i=0;i<10;i++)
if(strcmp(t,stun[i])==0){
printf("%s is in this class...\n",t);
break;
}
if(i>=10)
printf("No found %s!\n",t);
return 0;
}
运行样例:
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询