|
发表于 2022-9-8 17:45:39
|
显示全部楼层
本帖最后由 jackz007 于 2022-9-8 17:48 编辑
- #include <stdio.h>
- #include <string.h>
- int main(void)
- {
- char st[5][100], ch ;
- int i , j , min , max ;
- for(i = 0 ; i < 5 ; i ++) {
- printf("请输入第%d句话:", i + 1) ;
- for(j = 0 ; (ch = getchar()) != '\n' ; j ++) st[i][j] = ch ;
- st[i][j] = '\0' ;
- }
- printf("你输入了下边5句话:\n");
- for (i = 0 , min = max = 0 ; i < 5 ; i ++) {
- printf("%s\n" , st[i]) ;
- if(strlen(st[i]) > strlen(st[max])) max = i ;
- if(strlen(st[i]) < strlen(st[min])) min = i ;
- }
- printf("其中最长的是:%s\n", st[max]) ;
- printf("其中最短的是:%s\n", st[min]) ;
- }
复制代码
这个代码用 VC6.0、tdm-gcc 编译均无任何警告
tdm-gcc:
- D:\[00.Exerciese.2022]\C>g++ -o x x.c
- D:\[00.Exerciese.2022]\C>
复制代码
VC 6.0
- D:\[00.Exerciese.2022]\C>cl x.c
- Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
- Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
- x.c
- Microsoft (R) Incremental Linker Version 6.00.8447
- Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
- /out:x.exe
- x.obj
- D:\[00.Exerciese.2022]\C>
复制代码 |
|