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

53 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
int main()
{
    char a[100];
** **** *** * ** * * ** * * * * *** ** ***
    int len = strlen(a),i,j,k,l,x=0,y=0,z=0;
* * ***** ** * *** * *
    {
** ** * ** * *** * * * *** * ** *** ** ** ** * *
******* ***** ******** *** *** ** ***
* * ** ** * ** * * * * *** ** * * ** ** * *** * ** ** * ***** *** **
****** * * * * * *** *** ** ** * ** ***** * *** * ** * ** * * ** ** * * ***** ** *****
* * * * * * * * ** * * * * ** * * *** *
* * * * * ** * ** * *** * ** *** * * ** *** * * **
** *** **** * ** ** * ** * * * * ** * * *
***** ***** ** ** ** * ** **** *** * ** ** * * * * ***** ****** * || 'a'+k==a[i])
* * ** ** **** ******* * ****** * *** * * * ***** ** * * *** * **** **** ** * ** * *
*** * * * * * *** **** * * ** *** ** **** * **
* * * ** * * * * ** *** *** ** ** * * = len-x-y;
    }
* * * ** ** * *** *** ***** ** * *** *** *
* * * * ** * * * ** **** ** ** ******* ** *
**** ** ** * *** ** * * * * * * * **** *
    return 0;
}
answered by (-140 points)
0 0
prog.c: In function 'main':
prog.c:17:23: error: expected ')' before 'a'
             if('A'+k++a[i] || 'a'+k==a[i])
                       ^
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main()
{
**** ** * * * ******* ** * str[100];
    int count1=0,count2=0,count3=0,length,i;
** ** ** * ***** * * * * * **** *** * str);
* *** ** * * **** * *** ***** *
** * ***** ** *** * ****** (i=0;i<length;i++)
    {
* ** * ** * * * * * * * ***** ** ** * * ***
** *** * ***** * * * *** * ** ** ** **** * *
*** * *** * * * ** * * * * ** *** * * *** ** **** ** *
*** * *** * * * * **** *** ** * * *** **** *
** * ** * ** *** *** **** * ** * ** ** * * ** *
* * * *** * ** ** ** ** * ****** * **
* * ****** * *** * * * ** **** ** ** *** ** * **** * ** * **** * * * * *
** * * * * ** *** **** * * * *** ** *
** * * * **** * ** * * ** * **** * * * * ***
** **** *** * * * ** ** ** * *** *** **** *** **
* * ** * **** * ** ** * * ** ***** * * ** ** **** ********
*** ****** * * ** **** * ** * *** * **** * **
    }
* * ** * **** ** * * *** ** * * * *** * ** count2);
* * * * * **** * ** * *** ** ** ** * count1);
* * * * ** * *** * ** * ************* count3);
* * * * * * 0;

}
answered by (-168 points)
0 0
prog.c: In function 'main':
prog.c:9:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[100]' [-Wformat=]
     scanf("%s", &str);
             ^
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
* ** ** * * ***** ** * * a[100];
* ** * * * ******** * *** *** *** *
*** * ** * * **** * * * len=strlen(a),i,j,k,x = 0,y = 0,z = 0;
    
* * * * *** * * * * *** i<len; i++)
** *** ** ** * * * *
** * ***** * ** * * ***** ** * ** * *** j<10; j++)
* * ****** ** ** * * ** * * * ** * ** *** *
* *** ** * * ** * ** * * *** * * ** * * *** * *** * * ('0'+j==a[i])
* *** * **** ** ***** *** * * ** **** * ** * *** ** ** ** * * ****** ** * ** **
* * * ** *** * * * * *** ***** * * ** ***** * *** **
* ** *** * **** ** ** ********* ** ** * * *** k<26; k++)
* * * * * ***** * ** * * ** * * * **** **
*** * * ** * * * * * * * * ** ** * * * ********* ** ('a'+k == a[i] || 'A'+k==a[i])
*** ** * * *** **** * * ****** ** * *** * **** * * * *** * * * ** * *** ** * ** ** *** *
**** * *** *** * **** *** * * * * ** ** *** ** **
** **** ** ** * * ** * ** * ** * **** ** * *****
* * *********** ** ****
    
****** * * ******** *** *** * ** *
**** ** ** * *** * * * * **** ** *** * ** * *****
** * * ***** *** *** ** * *** * * *** *******
    
* * * * * * **** ** ** 0;
}
answered by (-127 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()
{
* * * ** * * * * a[200]={};
    int n,i=0,abc=0,num=0,other=0;
* ** *** * * ** * *** ** *** * * * *** **
* ** **** ** * * * *** * * ** *** * * * * ***
* * * **** ** *
* * *** * * ** *
* * * ** ***** * **** (a[i]!='\0')
    {
* * ******* ** ** * ** ** * * * * ** (a[i]>64 && a[i]<91)
* * * * * * ** ** *** * ** * *** * *** *
* ** ** ******* * ** *** * ** * * *** * ** *** ********** ** *** * **
* *** ** * * *** * ****** * * **** ** * ** *
** ***** ** * ** * * *** * ** * **** * * ** * * ** if (a[i]>96 && a[i]<123)
*** * **** * * ** * ** * ** **
** * ** ** * ** *** * * *** * ** ****** * * * ** * ** *** **
* *** * * * * ** ** *** ** * * * ***** * **
* * ** * * * * * * * *** ** * * *** ** **** * *** * if (a[i]>47 && a[i]<58)
*** ** ****** **** * ** ** ** * * ******* ** ***
**** ** * * * ** * ** ** ****** ** ********* *** * *** ****** *** *
* ** *** * * ** * ****** * ***** **
* ** ** * * **** ** * * ***** **** *
    }
***** ** ** * *** **** * *
* ** * *** *** *** ** * *** ** **** * * * * *
** * * * * ** **** * * *** * * *** *** ** *
* * ******** ** ** *** * ** ******** ** *
* * * * * * ** *** ** ****** * 0;
}
answered by (-229 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>
#include <string.h>
int main()
{
    char A[999];
    int i,cha=0,dig=0,oth=0;
* * **** ** * * **** * * * ***
* * *** * * * **** ***** ** *** *** **
    {
* * * * * * * * **** ** **** * * * *** ** * ** ** * * *** ***
****** ** *** * * * * * * ***** * * * * ** * ** * ** * ** * * ** *
** ** ** **** * * * * ** * *** ***** **** * * ** *** ***** * * * *** *** *** * **** *** * * * *****
* *** ** ** * * * ** * * * * * ** ** *** ** * ** ** * ** ** * * *
*** ** ** ** * * **** **** * * **** * * ** * ***
**** *** * ** * *** * * * **** * *** * * * *** ***** *
    }
*** * * * * **** * * ** ** *** *** *
* * * * * * *** ** * *** *** ** * * *
**** * ***** *** ** ** * ** ** ** *
** ** ** ********* * 0;
}
answered by (-196 points)
0 0
prog.c: In function 'main':
prog.c:7:15: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
     for(i=0;i<strlen(A);i++)
               ^~~~~~
prog.c:7:15: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:7:15: note: include '<string.h>' or provide a declaration of 'strlen'
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
* * ** ** * ******
* * * ***** * ** * *
***** * ** *** ** *

int * * **
{
* * char **** *

* ** * * * **** * * * * ** * ** array);

* int len = **** **

* ** * * ** int **** * = 0;
* ** ** ****
* * ** ** * int * * = 0;
** * **
* *** *** int * *** * = 0;

*** ** * ** for(int i = 0; i < len; i++)
***** * * * * {
* * * ** ** ** * *** for(int j = 0; j < len; j++)
* * ** * * ***** * ** * {
* **** ** * * *** * * ** * ** == '0' + j **** *** *** array[i] ** * '9')
*** * * * ** * * * * **** ** {
* * ** * * ** ** ** * * * *** ** ** * ** **** ** ***
* * ** * ** ** * * * **** }
*** * * *** * ** * * * * * *** else * ** == 'a' + j * * **** array[i] *** * 'z' || array[i] == 'A' + j *** * * * *** * ** 'Z')
* * * * * ** * * * * * *** * ** * ** {
* ** * * * * ** **** * * ** * ** * * * ** * * ** *
*** ** ** * * *** * * * ** ** }
** **** ** * * * * *** * ** **** else
* **** * * * * * ** * * *** *** * * {
*** * * * ** * * ** ** ** * *** ** ** ** * * = len - ** * *** - * * *
* * * * ** * * * *** ** * **** * * }
* *** * ***** * * }
* * **** * ** }
* *** * * * * * ** ** ** *** * ** ** ****** * ** * * * ** *
}
answered by (-285 points)
0 0
Case 0: Correct output
Case 1: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main()
{
    char a[999],letter;
    int alphat=0,digit=0,all=0,other=0;

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

* ** * **** * *** * ****** * ** ** * ** * * **** ***
    {
** * ** ** * * ***** * * * * * ** ** * k;
***** * * ** * * ** * ***** * ** * * *** * ** * *
* * * ** * * *** *** * * * * * * **
* **** * ***** **** * ** ** * * ** * ** *** * ** **** * * **** * * * ** *
**** * ** * * * * ** *** * * * * * * ** *** ******** * ** **** ** * * *
* ** * * *** * *** * * * * * * *** ** * **
    }


** * * ** ** **** * *** **** **** ** * ** **
    {
** * ** ** * * * *** * *** ** *** * **** * k;
** * ** ***** ** ** ** ** * * * * * * * * ** ** *
** * * *** * ** ** ** * **** **
** * ** *** *** * ***** * ** *** * *** *** * * *** * * * * * *** * ** *
**** ** *** *** **** * ****** * * * ****** **** *** * * * * * ** ******
* * ** * * * ******** ** *** * *
    }

** * * * ** * * *** *** * *** *** * ******** * **** *** * * ***** *** * * *
    {
** ** * ** * * * ** ** *** ****** * * ** ** * k;
** * *** **** ** ** *** * *** *** * ** ** ** *** * *
**** ** **** ** *** ** * ** ********
*** * ** *** * * ** * **** * *** ** * * ** * **** * *** *** * * *
* ** * ** * ** * ** ** ** * *** ******** * ******** **** * ****** * * **
****** * * **** * ** **** * * * * * * ***
    }


    int k;
* **** ** * ** * *** * * ** ** ** ** **** ** *** * ** **** *
* * * * *** ** ** * * * ** * * *
* ***** ** * * * * * ***** ** * **** * ** * * * *** * **** *
*** * * * *** * ** ** * * **** ** ** **

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

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


    return 0;

}
answered by (-16 points)
edited by
0 0
Case 0: Correct output
Case 1: Correct 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()
{
    char a[1000];
**** * **** * **** * * * ***** * ** ** ** * *
    int l1=0,i=0;
    int d=0,e=0,o=0;
* **** * * *** * *** * ** **
* * ** * *** ** **** * * ** ** **
****** * ** * ** * * * * * * *** * * ** * *** * ***** *** * * ** ** * * * *** * ** ** *** * **
* ** * ** * *** * ** * ** ** * *** ** * ** ** ****** * * * * *** *** * * ** ***** *******
* * ***** *** ** ** *** * ** * ** **** * ** ** * * * * ** * ** * **
* * ** ** * ** * * ** ** * **** ** ** * ** * * ** * * * * * * ** * *** if(65<=a[i]&&a[i]<=90){
* *** * * ** * * * ** ** ** **** ** ** * *** *** * *** ***** * **** * **** *** * *
* * *** * * * * * **** * **** *** * ** ** ****** * * ** **
* * ** ** * **** ** ********* * *** *** ** ** * *** ** ** ** ** ** * * if(97<=a[i]&&a[i]<=122){
*** * **** ** * * *** ** * * ** * ** * *** ** * * * * ** *** *** ********* *** * * * *
* * * ** **** ** ******* ** *** * ** * ** ** * * * ** ***
*** ** * *** *** *** * ** ** * * * * * ** ** * * ***** * * * *
***** * * * * * * * ** ****** ** ** * * * * * *** ** * ** *** * * * * ****
* ** * *** * * * * **** ** ** ** ** * ***** *** ** **
    }
*** ** ** * * * * ** * * ** * ***
** * *** * ** ***** * ** ** ** * * * * * * * *
* **** * *** *** ********** ** * * ****** ** * * **
    return 0;

}
answered by (-329 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
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()
{
** **** ** * * ** *** a[100];
* ** ******* ***** ****** ***
* ** * ** * *** **** len = strlen(a),i,j,k,l,x = 0,y = 0,z = 0;

*** **** * * ** * *** * * ***** = 0 ; i < len ; i++)
    {
* ** * * * **** ** ** * * * * * ** ** ** = 0 ; j < 10 ; j++)
*** * * *** * * * * ** ** * * *
* ** **** * ** * ***** *** **** **** ** **** **** **** *** * *** == a[i])
** * * * *** **** ** ** * ** * ** ** * * * **** * ******** *** * * ** ** *** ****
* ** ** * * ** * ******** ** ******* ** *
* *** ** **** ** ** ** * * * **** * ** * * * ** = 0 ; k < 26 ; k++)
* * ** * * * * ** * * *** * ** **** * * * *
* * * ** * * * *** * *** ** ** *** * * * ** *** * * *** **** * == a[i] || 'a'+k == a[i])
********* **** ** * ** * ******* * * * * ** ** ** ** * ** ** *** * **** *** * ***** *
* * ** * ** *** ** ** * ** ** ****** *
** *** * * ** * ** * * ******* * * * * * * = len-x-y;
    }

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

* ** ** ** *** * ** **** * 0;
}
answered by (-284 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()
{
** * *** ***** *** * * a[100];
*** * *** * ** ** **** * * ** *
* *** * ****** *** ** **** * len = strlen(a),i,j,k,l,x = 0,y = 0,z = 0;

** * * **** * ** = 0 ; i < len ; i++)
    {
*** ****** * * ** ** ** ** * * ** * * ** * * * * = 0 ; j < 10 ; j++)
* * * ******* ** ** *** *** * * * ** ***
*** * * ** * * *** ** *** * * ** * * * **** == a[i])
* * ****** * * ************ * * ** ***** ** * * * ** * * * ** ** ***** ***** ** * * *
** ** ** * * ** * **** ***** *** **
* ** *** * * * * ** * ** * * * ** *** ** * = 0 ; k < 26 ; k++)
* *** * * * * * ****** * ** ** ***
* ** * *** * * ** * **** ****** ** * ** **** * * * * ** == a[i] || 'a'+k == a[i])
** * ** ****** *** ** * * * **** ** * ** *** **** * ***** ** ** * * * * * *** ** * *****
** * *** ** * * * ** * ******* *** * * *******
** ****** ** * ******* ** * *** * * *** * * = len-x-y;
    }

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

**** **** * ** ** * 0;
}
answered by (-108 points)
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.69.17.63
©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
| 7.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
| 7k 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
| 6.6k views
12,783 questions
183,442 answers
172,219 comments
4,824 users