本文目錄一覽:
C語言,如何實現輸入n行後判斷n行?
如果是自動判題系統,那麼輸入一對判斷一對就可以了
一定要實現集中判斷的話,按照現在的方式,做兩個for循環就好了
輸入放一個
判斷和輸出單做一次
順便說一下,結尾的true打錯了
c語言接下來咋寫啊咋知道行數?
統計字元串長度可以用strlen函數
遍歷每一行,記錄strlen最小的行下標idx即可
C代碼以及運行結果如下:
結果正確,望採納~
附源碼:
#include stdio.h
#include string.h
int main() {
char s[5][10];
int i, len, idx = 0;
for (i = 0; i 5; i++)
scanf(“%s”, s[i]);
len = strlen(s[idx]); // idx為最短字元串的行下標,len為最短字元串的長度
for (i = 1; i 5; i++) { // idx初始為0,從s[1]接著遍歷即可
if (strlen(s[i]) len) {
len = strlen(s[i]);
idx = i;
}
}
printf(“%s\n”, s[idx]);
return 0;
}
c語言一個程序可以判斷輸入文本的詞數 字元數和行數?
#includestdio.h
#includestring.h
#includectype.h
int main(void)
{
char c;
char prev;
int n_char=0;
int n_word=0;
int n_line=1;
int p_line=0;
int inword=0;
printf(“please enter test to be analyzed(‘+’as an end)\n”);
prev=’\n’;
while((c=getchar())!=’+’)
{
n_char++;
if(c==’\n’)
n_line++;
if(!isspace(c)!inword)
{
inword=1;
n_word++;
}
if(isspace(c)inword)
inword=0;
prev=c;
}
printf(“字元長度是%d,詞數%d,行數%d\n”,n_char,n_word,n_line);
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/231463.html