0 like 0 dislike
13.4k views

Please write a program, the user will enter a line of characters, then the program will calculate number of digits, alphabets and another characters.

寫一個程式 輸入一個字串,計算字串裡的數字、英文字母和其他符號的次數。

Example input:

1234567890Ancdefghijklmnopqrstuvwxyz~!@#$%^&*()_+

Example output:

digit:10
alphabet:26
other:13

 

[Exercise] Coding (C) - asked in Chapter 13: Strings by (5.2k points)
ID: 40715 - Available when: 2018-01-04 18:00 - Due to: Unlimited

edited by | 13.4k views

53 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>

int main(){
** * ** **** * * * ** * * str[500];
* ** * ** * ** * * ***** ** sizeof(str), stdin);
** ** ** * * ** * i=0;
**** * ** ** ***** d=0,a=0,o=0;
*** ** * ******** * ** * ****
* * **** * *** * ** * *** * * * ** * ** * * * * ** * ** **** **** * * **** * d++;
*** * ** * * ****** ** ** ** * ******* * * ** * ***** * *** * * ********* * ** * ** * * ** * * *** * ** * *** **** a++;
**** * * ** ** * * ******* * ** * * * ** o++;
** * *** ** * * **** ** **** * * * * * ** * ** ** **
    }

* ** ** ** * * * ** * * **** * * **** *** * ** * * *

** ** * *** ** * * * *** 0;
}
answered by (-116 points)
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main(){
**** ** *** ** ** * * str[500];
*** ** *** **** * *** * * ** sizeof(str), stdin);
* * * *** *** i=0;
* **** * **** ******** d=0,a=0,o=0;
* * * * *** ** * **
* ** * * *** ** * * ** * ** ** * *** * **** ***** * ****** * * * d++;
* * * ** * ***** ** * *** * * * **** * *** * * * * * * * ***** * ** *** ** ** * ** * * * * * * * * ** * a++;
* * * * *** ** * * * ** ********* * * * o++;
* * *** ** ** **** **** *** **
    }

** ** *** **** * * ***** ******** ***** ***** ****** *** * * **** // remove enter count

* * * * *** * * 0;
}
answered by (-116 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 like 0 dislike
Hidden content!
#include * **** * ** *
#include * * **

int main()
{
******* * * ** ** * * A[1000];
** ** ***** * * * *** i, digit=0, * * other=0;
* ** * * * * ** *** * * 1000, stdin);

* ** ** ** ****** *** ** **** **** * * i++)
**** * * * ** ** * **
** *** ***** * ** * ** *** * * * * ** >= '0' * ***** * A[i] <= '9')
** *** *** * * * * * * *** * * * * ** * * * * ** * * * * = digit + 1;
** ** ** ** * ** ** * * * * * ** * ** * ** ***** ** if((A[i] >= 65 * * **** A[i] <= 90) || (A[i] >= 97 ** *** * A[i] <= 122))
* * * ** ** ** *** * * *** **** *** ** * * ** * *** *** ** * *** * ** * = alphabet + 1;
* * **** *** * * * * * * *** * * if(A[i] > 31)
* * **** *** * * ** * * * * ** **** * * *** ** ** * * * * = other +1;
* *** * * ** ** *

*** **** *** ** * ** * ****** * * ** **** * *** * * * digit);
* * * *** ** *** *** * * * * * ** ** * *** alphabet);
*** *** * ** * *** * ** ** **** ** **** ********* other);

***** * * * * * *** ** * * 0;
}
answered by (5.2k points)
0 0
prog.c: In function 'main':
prog.c:8:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(A);
     ^~~~
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/ccSj5aoA.o: In function `main':
prog.c:(.text+0x44): warning: the `gets' function is dangerous and should not be used.
0 0
prog.c: In function 'main':
prog.c:8:7: error: assignment to expression with array type
     A = getchar();
       ^
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.120.163
©2016-2025

Related questions

0 like 0 dislike
53 answers
[Exercise] Coding (C) - asked Jan 4, 2018 in Chapter 13: Strings by semicolon (5.2k points)
ID: 40713 - Available when: 2018-01-04 18:00 - Due to: Unlimited
| 11.6k views
0 like 0 dislike
27 answers
[Exercise] Coding (C) - asked Jan 11, 2018 in Chapter 13: Strings by thopd (12.1k points)
ID: 41439 - Available when: Unlimited - Due to: Unlimited
| 10.1k views
0 like 0 dislike
44 answers
[Exercise] Coding (C) - asked Jan 4, 2018 in Chapter 13: Strings by semicolon (5.2k points)
ID: 40714 - Available when: 2018-01-04 18:00 - Due to: Unlimited
| 10.2k views
12,783 questions
183,442 answers
172,219 comments
4,824 users