C語言:統計數字空格其他字元程式
#include <stdio.h>
int main()
{
char t;
int num=0;
int spac=0;
int other=0;
int sum=0;
printf("Please input:\n");
while(1)
{
t=getchar();
sum++;
if(t>='0' && t<='9') num++;
else if(t==' ' || t=='\t') spac++;
else other++;
if(t=='\n') break;
}
printf("nums is %d\n",num);
printf("spaces is %d\n",spac);
printf("others is %d\n",other);
printf("sum chars is %d\n",sum);
return 0;
}
相關推薦
C語言:統計數字空格其他字元程式
#include <stdio.h> int main(){ char t; int num=0; int spac=0; int other=0; int sum=0; printf("Please input:\n"); while(1) { t=getchar(); sum++; if
【C語言】統計數字在排序數組中出現的次數
語言 個數 統計 ret r+ () class tdi times //數字在排序數組中出現的次數。 //統計一個數字在排序數組中出現的次數。比如:排序數組{1,2,3,3,3,3,4,5}和數字3,因為3出現了4次,因此輸出4. #include <stdio
C語言:統計學生成績並輸出
統計學生成績並輸出最高分 題目要求:有50名學生,每個學生的資料包括學號,姓名,3門課的成績,從鍵盤輸入50名學生資料,要求打印出每門課的平均成績,以及三門課總分最高的學生資料(包括學號,姓名,3門課的成績,3門課的總分)。 #include<stdio.h> #defi
C語言:將數字轉化為字串
#include<stdio.h> #include<assert.h> #include<string.h> //123====>“1 2 3” 將數字轉化為字串 char *my_itoa(char *str,i
C語言:念數字(結構體)
輸入一個整數,輸出每個數字對應的拼音。當整數為負數時,先輸出“fu”字。十個數字對應的拼音如下: 0: ling 1: yi 2: er 3: san 4: si 5: wu 6: liu 7: q
c語言:判斷數字整數為幾位數
#include <stdio.h> int main() { long long a; int count=0; printf("請輸入一個整數:"); scanf("%lld",&a); while(a
c語言:輸入一行字元,分別統計出其中英文字母、空格、數字和其他字元的個數。
輸入一行字元,分別統計出其中英文字母、空格、數字和其他字元的個數。解:程式:#include <stdio.h>int main(){char c;int letters=0,space=0
C語言:輸入一行字串統計出英文字母,空格,數字和其他字元的個數
題目要求 輸入一行字串統計出英文字母,空格,數字和其他字元的個數。 程式分析 要統計英文字母,空格,數字和其他字元的個數,則要遇到他們加一。 核心程式碼如下: while ((c=getchar())!='\n') { if ((c >= 'a' &
輸入一行字元分別統計出其中英文字母、空格、數字和其他字元的個數。(用c++語言編寫程式)【寫的第1篇部落格,很高興
#include<stdio.h> int main() { char ch; //定義ch為字元型變數 int a=0,b=0,c=0,d=0; //定義a,b,c,d為整型變數並賦初值 while(scanf("%c",&ch),ch!=’\n’) //輸入字元直到c
C語言:編寫一個程式統計輸入字串中,各個數字、空白字元、以及其他所有字元出現的次數。
#include<stdio.h> int main() { int c = 0; int num_count = 0; int emp_count = 0; int els_count = 0; w
【C語言】統計一個字串中字母、數字、空格及其它字元的數量
統計一個字串中字母、數字、空格及其它字元的數量 解法1: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> void Count(con
C語言:找出一段話裡面的大寫、小寫、空格、其他字元的個數
C語言:找出一段話裡面的大寫、小寫、空格、其他字元的個數 我是一名在校大學生,初次寫部落格,希望各位大佬不喜勿噴,這個小程式,僅供參考,希望對大家有所幫助。 首先,分析題意,我們需要將一段話裡面的大寫、小寫、空格、其他字元的個數統計出來。 我們需要儲存一段話,大小為3行,每行
C++練習之 統計英文字母,空格,數字和其他字元的個數
#include <iostream> using namespace std; int main() { int a,b,c,d; char k; for(a=0,b=0,c=0,d=0;(k=getchar())!='\n';) { if((k&
python實現:輸入一行字元,分別統計出其中英文字母,空格,數字和其他字元的個數
s=input('input a string:\n') letters=0 space=0 digit=0 others=0 for c in s: if c.isalpha():
ACMNO.8輸入一行字元,分別統計出其中英文字母、空格、數字和其他字元的個數。 輸入 一行字元 輸出 統計值 樣例輸入 aklsjflj123 sadf918u324 asdf91u32
題目描述 輸入一行字元,分別統計出其中英文字母、空格、數字和其他字元的個數。 輸入 一行字元 輸出 統計值 樣例輸入 aklsjflj123 sadf918u324 asdf91u32oasdf/.';123 樣例輸出 23 16 2 4
輸入一行字元,分別統計出其中英文字母、空格、數字和其他字元的個數
#include <stdio.h> int main() { int a,b,c,d,ch; a=b=c=d=0;//計數器初始化為0. while((ch=getchar())!='\n')//迴圈讀取字元,到換行結束。
輸入一行字串,要求統計其中字母,空格,數字以及其他字元的數目
#include <stdio.h> void main() { int letter, space, digit, other; char ch; letter = space = digit = other = 0; while ((ch
輸入一行字元,分別統計出其中英文字母、空格、數字和其他字元的個數。
#include <stdio.h> void Fun(char c) { int letters=0,blank=0,digit=0,other=0; while ((c=getchar())!='\n') { if (c&
輸入一行字元,分別統計出其中英文字母,空格,數字和其他字元的個數
#include #include <string.h> using namespace std; int main() { char str[50]; int l=0,b=0,n=0,o=0; //l=letter,b=blank,n=numb
python實現 輸入一行字元,分別統計出其中英文字母,空格,數字和其他字元的個數
s=input('input a string:\n')letters=0space=0digit