正在加载图片...
11.1.1程序解析运行结果1#include<stdio.h>Input a color:yellow#include<string.h>指针数组int main(void)position:3int i;1char*color[5] = {"red","blue","yellow","g运行结果2char str[20];printf("Inputa color:");Input a color:purplescanf("%s", str);Not Foundfor(i= 0; i< 5; i++)if(strcmp(str,color[)==0)/*比较颜色是break;if(i < 5)printf("position:%din", i+1);elseprintf("Not Foundin");return o;711.1.1 程序解析 #include<stdio.h> #include<string.h> int main(void) { int i; char *color[5] = {“red”, ”blue”, ”yellow”, ”green”, ”black” }; char str[20]; printf(“Input a color:”); scanf(“%s”, str); for(i = 0; i < 5; i++) if(strcmp(str, color[i]) == 0) /* 比较颜色是否相同 */ break; if(i < 5) printf(“position:%d\n”, i+1); else printf(“Not Found\n”); return 0; } 运行结果1 Input a color:yellow position:3 运行结果2 Input a color:purple Not Found 指针数组
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有