0 like 0 dislike
16.6k 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 | 16.6k views

53 Answers

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

int main()
{
    int p,num=0,abc=0,other=0,i;
*** * ** ******* * **** *** a[1000];
* *** ** * * ** * * *******
* * * * * * * ***
 for(i=0;i<p;i++)
* * ** * ***** ** *** * * * * ** * * *
* * ** ** * * ** * * * * ******* * ** * * ** ** *** ** && a[i]>47)
*** * * **** * * * ** * *** * ** *** ** *** * ***** ****** * *** * ******** * ** ** *** * ***
* ** * ** * *** ** * * ***** * *** *** ****** * * **** * ** * **** *** *** if(a[i]<91 && a[i]>64)
* ** ** * *** * * * **** **** *** ** *** **** * **** ****** ** * * *** ** *** *** ** **
** ** ** * * * *** **** * * ** *** ** * **** * * *** * * * ** ** * **** ** if(a[i]<123 && a[i]>96)
* *** * * **** * ** ** * * ** * *** **** * *** *** ********** * *** *** **
*** *** ** *** ** * * *** ***** ********* * *** *** **** ** **** * * ** * * *** ** * *** * **

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

int main()
{
    int p,num=0,abc=0,other=0,i;
* ***** ***** * ** ** a[1000];
** **** ** * **** * ***** **
* * *** ** * *
 for(i=0;i<p;i++)
* * *** ** * * * **** ****** ** *** * * **
* * ** * * ** ** * * **** * ** ** ** * *** *** ** * * **** * && a[i]>47)
* ** ** * ** * *** *** ** * * **** * ** *** * * * * ***** *** ** * * **** * *
* ** * ******* **** * ******* * * ** *** * ** ** ** ** ** **** *** * if(a[i]<91 && a[i]>64)
*** * * * ****** * ** *********** * ** ** * ******* * * ** * * * *** ** ** **** ** * * *
*** ** * ***** * * ** * ** *** ** ** ** * **** * ** * ** * ** * ** * * if(a[i]<123 && a[i]>96)
** * * * ** ***** * *** ***** *** * *** **** ** ** *** *** * * *** ** * *** **** *
* * ***** * *** * * *** ** * * * ** ** ** * * * ** * ** ** * ** * *** **** * ** ** ** * * *

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



int main()
{
    int n=0,j;
    int alphabet=0;
    int digit=0;
    int other=-1;
    char word[1000];
*** ** **** *** ** * * **** ***
** * ** * ** * *** * ********* * * ****** //strlen is array ,begin from 0
* ** * ****** **** ** **** ** *** ** * * **
* ** ** * ** **** *** * * * ** ** * * * ****** ******** * * ** ** * * && word[n]>=97)
* ** ***** * * * ** ** * * ******* * *** * * ** ***** ** ******** * * *
* * * * * ****** *** * ** * * ** * *** ** * ** ** * * * ** * ** * ** ** * * * * *** * * ** * * * * ** * * * *
* ** ** * **** * * * * ***** * ** * * * * ***** * * * * * * * * ** ** * * *
***** ** * * ***** ** * *** ** ** * **** ** ** * * * ** * * * *** * *** * if(90>=word[n] && word[n]>=65)
* * * * * *** * * * **** * * * * * *** ***** * ** **** * * ******** **** *** * **
*** ** **** * *** * * *** * * *** * * * ** ** *********** * ** * * ** * ** * * * ** * ** * * * **
* *** * * *** ** * * *** * *** *** * * * ** * * ** ***** ** *** * * ** **** *

* * ** * * ******** ** * * * * * * * * * ** * ** * if(57>=word[n] && word[n]>=48)
* * * ** * * * * ******* * * * ** * ** ** * ** * * **** * ****** ***** ** * *
**** * * * * * * ** **** *** * ** * * * ** ** * **** *** * ** * * * ** * ** * ** * * * ***
** * *** * * ** * * ***** * * * *** * * * *** * * * * * ** * *** * * ** *

* *** * * ** ** * * ***** * * **** *** ** *** ** ** * * * * other++;


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

}
answered by (-301 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include <string.h>



int main()
{
    int n=0,j;
    int alphabet=0;
    int digit=0;
    int other=0;
    char word[1000];
** *** ***** ** ** * * * ** *
** * ****** * * * * * * *** *** * ** * //strlen is array ,begin from 0
* * *** * ** * *** * *** **** ** * **
* **** **** ** * ** *** * ** * * * * * *** ** * *** **** && word[n]>=97)
* * ** ***** ** * *** *** *** *** ****** ****** * ****** *** **** *** ** ***** * * * * ** * ** * * ***
*** * * * ** * * * **** * ** ** **** * **** ** * * ****** * * ** ** *** * ** * ** ***** ** ** * * * * ** *
* * * * *** * * * ** *** ** *** **** * * * * * * * * * * * ** * * ** * * ** ** * ** ** *
* * * * ** * * * ** * * ** *** * * * ** * * * ** * * ** *** *** * if(90>=word[n] && word[n]>=65)
* * * ** ****** * * ** * * * * * ** *** * ** ** ***** * ** **** *** ** * *** * ** * *
**** ** ** ** ****** ** * ** **** ** ** * * * * * * * ** * * ** ***** * * ***** **** **** * *** **** ** * **
**** ** ** *** * * * * * *** *** ******* *** * *** * * * ** ** **** * ** ** ** * ** *

* * * ** * * ****** * * * * ** ** * * ** ** * ** * ****** if(57>=word[n] && word[n]>=48)
**** * * * ** *** * *** * ** * ** * * * ** * * * * * ** ** ** * *** *** * * * * *
******* * * ** * ** * **** * ** *** * ** * ** * *** * * * * * * *** **** ** *** * ** * **** * * * * *** *
* * ** ** * * * ** * ** * **** * ** ** * * ** ***** *** ** ** * * ****** ** * * ****

* ** * *** **** **** * * *** ** * ** * **** * ** ** other++;


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

}
answered by (-301 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include <string.h>



int main()
{
    int n=0,j;
    int alphabet=0;
    int digit=0;
    int other=0;
    char word[1000];
*** ** ** *** ** ** **** * **** **
******** **** * *** * * * ** * * * * * * //strlen is array ,begin from 0
*** * ****** * *** ***** * ** ** **** *
***** * * * * *** * * **** * * * * * * * * * * * *** ** * ***** * * * ***** && word[n]>=97)
** * **** ** * * * ** *** **** **** ** ** ***** ** * ** *** * * ** ** * * * *
** * * *** * *** ** ** * **** *** **** * * ** * * * ** **** * *** * * * * * * ** *** * ******** **** * *
* * **** ** *** **** * ** ** * ** ***** * * * * * * * ****** * * * * *** * *
* * * **** * * * *** * *** *** *** * * * * * * * if(90>=word[n] && word[n]>=65)
** * ** * ***** *** * * * * ** *** *** ** * **** *** * ** * *** * *** * **** ** * **
**** ** * * * * ** * * ** ****** * ** * * * *** ** *** * * ** * *** ** * ** ** ***** *** * ** * ***** * *
** * * **** * * **** *** * *** * *** ** * * * * * * ** * * **** ***** * *** * ***

**** ****** * ** ** *** * ** * * *** * *** * * * * *** ** ** * ** if(57>=word[n] && word[n]>=48)
* * * ** * **** * * **** *** * ** * * ** * * * * * *** * * ** * * * *
* * * *** * ** * ** ** ** * * *** *** ** *** ***** ** **** ** * * *** * * * ** ** * * * * * ** **
** ** ***** *** ** *** * ** * * ** * * **** * ** *** ** ***** ******** ** ** **

* *** * * **** ** * * ** *** ** ******** ** **** ** *** ** * * * other++;


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

}
answered by (-301 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{
    char a[100];
    int di=0,al=0,ot=0,len,i=0;
**** * * ** ** ** * * **** **
    len=strlen(a);
* ********** * * * * ** *
    {
* *** * *** ** * * * *** **** ** ** ** * * * ***** * ******* * ***** * * *
* *** ** *** ******* ******* * * *****
**** * ** ** ** ** * ** * * * *** *** * **** ** ** ** *
* ** * * * ** * ** * * ***** ******** * **** *
* * * * * *** * ** **** ** **** ***** * * * ** *** ** * ** * **** * * **** **** ** * *** * ** ***** ** * *** * * * * * **** ** ****
** * * **** * ** * * * ** *** ***** * *
* ** **** * * *** * * *** ** * * * *** * **** * * * *** ** *
* ****** ** * ***** * ** *** * * * * **** **
* * ** * ** *** ******* ** * * ** * * * ***
* ** **** *** *** **** * **** * * *** * *
* * * ***** * *** ** * * * *** ** * ** * ***** * ** * * * ** * *** **
*** * * * **** ** ** * *** ** *** ** *
    }
* ** * ***** * * * *** * ** * * ** * * ** *** *
***** *** * * * * ***** * *** ** * * ** * *****
* ** ** *** * ** ****** ** * *** *

}
answered by (-255 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{

    int i,digits=0,alphabet=0,other=0;

    char str[100];
* ***** * * * ** * *** *** * *

* * * ** ** * ** *** * ** ** ** *
    {
* * ** * *** **** **** ***** * * * ** ** ***** ** *** * * * * * ** ** * ** * * ** ****** ** ** * * **
* * * * ** ** ** ***** * ** ** * *** * ** ***
* * * *** * *** * ** * ** * * ** *** ** ****** *** *
* * ******** ** ** ***** ***** ** *** ** * * **
* *** * * ** * * * * * * * ** * *** ******** * *** &&str[i]<='9'){
* * * * * **** *** ** ***** *** *** ****** *** ** * * *** * **
** ** * * ** *** * * * ** * * ** * **
* *** * ** ** *** * * * ***** * ** * * **** ** * * * ** ** *** * * ******* * * **** * * *** * **** *** ** **** *** * ** ** **** ***** ** ** *** *** * *** ** * **
** * ****** ** * ** ** * * * ** ** * * ** *
** ** * * * ** *** * * * * * * * * * * ** * * * ****** ** ** *
* **** * ** **** ** ** * * * * * *
    }
********* * * ** ****** * * ** *** * * ** * * *
** * * * * ****** * **** ** ** ** ** ** *
* **** * ** **** * * ** ** *** *** **** *

    return 0;
}
answered by (-167 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
* * *** ****** * ** * ** str[1000];
* * ** * * * ** * * * ** n,i,digits=0,alphabet=0,other=0;
**** *** ** ** **** * ***** *

* * * * ** * * ** * ** ** *
    {
**** * * *** * * * * * *** * *** **** * *** * * ** ** && str[i]<='Z'|| str[i]>='a' && str[i]<='z')
*** * * * * *** * ** ****
* * ** *** ** ** * * ** ** *** * * * * * ** ** * * *** * **
* ***** ** ** ** ** * * * ** * ** * **

* * * **** * * * * ** * ** * ** ** *** * if(str[i]>='0' && str[i]<='9')
** * * ***** * *** * ****** ** * * * * **
*** * * * * * *** * ** ***** * * * *** *** * *** *** ***** ***** *** * * *
*** * * * * *** *** * ** ** ** ** * * *
** * *** *** * * *** * * ** * *** ***** *
* * ** ** ** * * * * * ****** * ***
* **** ** *** ** * * ***** ** *** * **** * ** ** ** * * ** * **
** *** ** * * * ** * ** * ** * * * *** *

    }
* * ** * * ** **** ** ** ***** *** ** ** * ** ** ***** ** * ** * **
}
answered by (-323 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
****** ** ** * ******* str[1000];
**** * * ** * * ** ** * i,digits=0,alphabet=0,other=0;
** * ** *** *** ***

******* * **** * ** * * * ** *****
    {
* ** *** ** * *** ** *** * ** * ** *** * ** && str[i]<='9')
* *** ** * * * *** ***** * * * *** * *** * * **
*** * **** ** * ** * ** ** * ** * **** * ** ** *** ** ** * * ***** *** **
** ** *** ** *** **** *** * *** * ** ** **** **
*** * * * * ** ** ** * * * * ** * if(str[i]>='A' && str[i]<='Z'|| str[i]>='a' && str[i]<='z')
** * * * * ** ** **** * *** *** * * *********
** * ** ** * * **** * * ** * *** * ** *** ** * ** ***** * *
**** * ** ***** * * * ** * * * ** **
** * * **** ** **** * * * ** ***** *** *** *** ** *
** * *** * ** * ** * * *** ** **** *
* * * *** * * * * ** **** * * * * **** * * * ** *
* * ** ** * * * ** *** * * ** * *

    }
****** ** * * * **** ** *** * ** ** * * ** * * ** * * *** **** *
}
answered by (-323 points)
0 0
prog.c: In function 'main':
prog.c:6:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(str);
     ^~~~
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/ccMOc1sy.o: In function `main':
prog.c:(.text+0x43): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{

    int i,digits=0,alphabet=0,other=0;

    char str[100];
* *** *** * * * * ** **

** *** * * * * * * **** * **** * * ** *
    {
** **** ** * *** * ** * **** **** ** * * * ** * * ** *** * ** * *** * *** **** * ** * * ** *** * ** *
*** ** ** * * **** * *** ***** ** *
** * ** * ** * * * ** ** ** ** ** ** * **** *** * * * *
* ***** * * ** *********** **** * **
*** * * ***** * **** *** * * * * **** ** * * * ****** ****** &&str[i]<='9'){
* *** * *** ** * * * **** *** * * * * ***** * * ** *** *********
* ** * * * * * * * ** ******* * *
** **** * ** * * * ** ** ** *** * * * ***** * ** ** ****** * *** *** * ** ****** * * ** * * ** ** * * **** * *** * *** * * ** * ** *** * * *** *** * * **** * ****** * *** * *
* * ** * ** * * **** * * * * *
** ******* *** * ** *** ** * **** ** * * * ****** ****
** * * * ** * * ** * * ** ** ****
    }
* *** ***** * ** **** ** * ** ** ***** **
** ** * * * * ** *** * * * *** * ** * * ****
** * ** * * ** ** * * * ** *** * ** ** * * **
    
***** * * ** * ** * 0;
}
answered by (-167 points)
edited by
0 0
prog.c: In function 'main':
prog.c:28:5: error: expected declaration or statement at end of input
     return 0;
     ^~~~~~
0 0
prog.c: In function 'main':
prog.c:28:5: error: expected declaration or statement at end of input
     return 0;
     ^~~~~~
0 0
Case 0: Wrong output
Case 1: Wrong output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:104.23.197.65
©2016-2026

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
| 13.9k 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
| 13k 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
| 12.1k views
12,783 questions
183,442 answers
172,219 comments
4,824 users