2 like 0 dislike
5.7k views
計算字數

在英文中,被空白隔開的就會算是一個單字,所以

This is a pen.

這個句子中共有4個單字,請寫一個程式,計算輸入的句子共有多少個單字

輸入說明:

輸入一個句子,輸入會以一個句點.作為結束

輸出說明:

輸出一個正整數,表示輸入的句子共有幾個單字

輸入範例:

This is a pen.

輸出範例:

4
[Exercise] Coding (C) - asked in 2017-1 程式設計(一)AD by (18k points)
ID: 33762 - Available when: Unlimited - Due to: Unlimited

edited by | 5.7k views

24 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
* * *** ** * * ** * * **** *** * * ***** * ** * input[100];
        int i,count,len;
* * *** * ** ** ************ * ** ** * ** * ** *** ** *
* * * * * * * ** ** ***** * **** * *
** * ** * * * *** * * ** * ****** * * **** ****** ** *** ** * ** * * ***
** ****** * * ***** * *** * * * * **** * * ** **** * *** *** *
** * * * * ** * * * * ** * * * *** * ** ** ** ***   count=1;
* *** ** ** **** * * ** *** * * ** ** * * *** *** ** * **** *
* * * ** * * * * * * **** ** ** * *********** * * **** *
* **** *** * * ** **** * * * * * * * ** **** * ******** *** *** * * * ** * * ** * ***** *** *** * ***
** *** ** * **** * * * * * * ****** **** * **** * * * ****** * * * * **** * *** ** ** *** * * * * * ** ** ** * *
********* * ** * **** ** *** * * ** ** *** **** ** *
            printf("%d",count);
* * ** **** * * *** ** * * ** ***** ** * * **






    return 0;
}
answered
0 0
prog.c: In function 'main':
prog.c:8:37: warning: comparison between pointer and integer
         while(fgets(input,100,stdin)!=EOF)
                                     ^~
0 like 0 dislike
Hidden content!
* * * * ****
* * * * * * *
int main()
{
* ***** ******* int i,n=1;
********* *** ** char ch[999];
* *** ** *
* ** * ** ** * * * *
** ** **
* *
    ** * * * *
** **   {
**** * * * * *** ** * ****
* * * **** *** ** {n++;}
* * * ** * * * * *** * *
** * ** }
* * ** * ****
** ** * * ** * * *****
* * **
* **** *** **
* * ** ** * **** ** ** * *** * **
** **** * **
}
answered by (192 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 like 0 dislike
Hidden content!
*** * **** *
* *
int main()
{
** * * * int i,n=1;
* * **   char ch[999];
* * ** ** *
* * ** ** * gets(ch);
* * * * ***** **
** ** *
** * ** * **** * * **
*** **   {
**** * *** ** * * * * * * * * ***
* *** ** * *** *** ** * {n++;}
*** **** ** ****** *** **
* * ** *** }
** ****
** * *** * **** **** * * *** **
** *** *
**** ** ****
* ** * * ** * * *** * ****
* *****
}
answered by (192 points)
0 0
prog.c: In function 'main':
prog.c:8:2: warning: 'gets' is deprecated [-Wdeprecated-declarations]
  gets(ch);
  ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
/tmp/ccz9y9O4.o: In function `main':
prog.c:(.text+0x2f): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
*** ** * *** **

int main()
{
*   int i,n=1;
* *** *** char ch[999];
* * *** **
** * ** gets(ch);
**
* * ** * **
* * *** ** * *** * * * ***
** ** * * {
***** *** * * ***** **
** *** ** * ** ***** * {n++;}
** ** * * **** * ** * ** *
*** ** * ** * }
** ** **
**** * ** * * * ** * * * * ***
** * ******
* ** * *
** * * *** ** **** ***** * * * * * * *
* * * ** * * ***
}
answered by (192 points)
0 0
prog.c: In function 'main':
prog.c:8:2: warning: 'gets' is deprecated [-Wdeprecated-declarations]
  gets(ch);
  ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
/tmp/ccGAlNZ8.o: In function `main':
prog.c:(.text+0x2f): warning: the `gets' function is dangerous and should not be used.
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.214.204
©2016-2025

Related questions

3 like 0 dislike
20 answers
[Exercise] Coding (C) - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 33758 - Available when: Unlimited - Due to: Unlimited
| 5.3k views
3 like 0 dislike
22 answers
[Exercise] Coding (C) - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 33757 - Available when: Unlimited - Due to: Unlimited
| 6.7k views
3 like 0 dislike
9 answers
[Exercise] True/False - asked Nov 16, 2017 in 2017-1 程式設計(一)AD by 楊修俊 (30k points)
ID: 33763 - Available when: 2017-11-16 14:00 - Due to: 2017-11-16 14:30
| 1.2k views
3 like 0 dislike
6 answers
[Exercise] Coding (C) - asked Nov 30, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 34979 - Available when: Unlimited - Due to: Unlimited
| 2k views
3 like 0 dislike
5 answers
[Exercise] Coding (C) - asked Nov 30, 2017 in 2017-1 程式設計(一)AD by Shun-Po (18k points)
ID: 34978 - Available when: Unlimited - Due to: Unlimited
| 2.1k views
12,783 questions
183,442 answers
172,219 comments
4,824 users