实验11-1-3 查找星期 (15 分)
#include <stdio.h> #include <string.h> #define MAXS 80 int getindex(char *s); int main() { int n; char s[MAXS]; scanf("%s", s); n = getindex(s); if (n == -1) printf("wrong input!\n"); else printf("%d\n", n); system("pause"); return 0; } /* 你的代码将被嵌在这里 */ int getindex(char *s) { char *days[7] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; for (int i = 0; i < 7; i++) if (strcmp(s, days[i]) == 0) return i; return -1; }

浙公网安备 33010602011771号