C語言程式設計(17)
題目:輸入一行字元,分別統計出其中英文字母、空格、數字和其它字元的個數。
1.程式分析:利用while語句,條件為輸入的字元不為'\n'.
2.程式原始碼:
#include "stdio.h"
main()
{
char c;
int letters=0,space=0,digit=0,others=0;
printf("please input some characters\n");
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",letters,
space,digit,others);
getch();
}
相關推薦
C語言程式設計(17)
題目:輸入一行字元,分別統計出其中英文字母、空格、數字和其它字元的個數。 1.程式分析:利用while語句,條件為輸入的字元不為'\n'. 2.程式原始碼: #include "stdio.h" #include "conio.h" main() { char
2018秋C語言程式設計(初級)作業- 第3次作業
7-1 找出最小值 #include<stdio.h> int main() { int min,i,n,count; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d",
Linux C語言程式設計(下篇) | gdb的使用
前兩篇Linux C語言程式設計(上篇) | gcc的使用和Linux C語言程式設計(中篇) | make的使用講述了在Linux下如何編譯得到可執行程式,那麼當程式執行結果不符合我們的預期時,如何進行除錯呢?這個時候就要使用到gdb工具了~ 1.gdb介紹 gdb也屬於GNU專案
Linux C語言程式設計(中篇) | make的使用
上一篇Linux C語言程式設計(上篇) | gcc的使用講述瞭如何使用gcc進行編譯,其中只是對hello.c這一個檔案進行編譯,那麼當我們需要編譯多個檔案的時候該怎麼做呢? 1.多檔案編譯例項 這個例子中分別在四個檔案(add.c, dec.c, mul.c, div.c)實現相
C語言程式設計(一)-基礎知識2
15. 程式設計是指從確定任務到得到結果、寫出文件的全過程16. 程式設計工作過程a) 問題分析b) 設計演算法c) 編寫程式d) 對源程式進行編輯、編譯和連線e) 執行程式,分析結果f) 編寫程式文件17. 程式包括兩方面的資訊a) 對資料的描述。在程式中要指定用到哪些資料
狀態機的C語言程式設計(轉)
一有限狀態機的實現方式 有限狀態機(Finite State Machine或者Finite State Automata)是軟體領域中一種重要的工具,很多東西的模型實際上就是有限狀態機。 FSM的實現方式: 1) switch/case或者if/else這無意是最直觀
linux 下C語言程式設計(2)——程序的建立,掛起,解掛,程序間通訊
在 linux 下利用C語言實現程序的建立,掛起和解掛操作 #include <stdio.h> #include <sys/stat.h> #include <sy
C語言程式設計(9)
題目:要求輸出國際象棋棋盤。 1.程式分析:用i控制行,j來控制列,根據i+j的和的變化來控制輸出黑方格,還是白方格。2.程式原始碼: #include "stdio.h" #include "conio.h" main() { int i,j; for(i=0;i<
程式設計菜鳥到大佬之路:C語言程式(五)
第五天學習精要 關係運算符和邏輯表示式 關係運算符 六種關係運算符用於數值的比較:相等 ==、不等 !=、大於 >、小於 <、大於等於 >=、小於等於 <=。 比較的結果是bool型別,成立則為true,反之為false。
程式設計菜鳥到大佬之路:C語言程式(六)
第六天學習精要 if語句 條件分支結構之if 語句 有時,並非所有的程式語句都要被順序執行到,會希望滿足某種條件就執行這部分語句,滿足另一條件就執行另一部分語句,這就需要“條件分支結構”。 依次計算表示式1、表示式2…只要碰到一個表示式i為真,則執行語
程式設計菜鳥到大佬之路:C語言程式(七)
第七天學習精要 for迴圈 for迴圈語句 for迴圈一般用於將某段程式碼(語句組)重複執行若干次。 第一步:計算“表示式1”。 第二步:計算“表示式2”,若其值為true,則執行“{ }”中的語句組,然後轉到第三步;若為false,則不再執行“{}”中的
程式設計菜鳥到大佬之路:C語言程式(八)
第八天學習精要 break語句和continue語句 break語句 可以出現在迴圈體中(for、 while、 do…while迴圈均可),其作用是跳出迴圈。 在多重迴圈的情況下,break語句只能跳出直接包含它的那一重迴圈。 例題:如果兩個不同
unix/linux程式設計實踐教程C語言補充(2)
1 getchar()和putchar()函式 getchar()函式的功能是從終端接受一個字元。可以將其置於程式中實現暫停功能。 getchar()函式接受的字元可以賦給一個字元型或整型變數,也可以賦給任何變數,直接輸出。 putchar(引數) 引數可以是一個字元
libxml2程式設計--C語言xml(1)
1、下載與安裝LIBXML2 Libxml2是一個C語言的XML程式庫,可以簡單方便的提供對XML文件的各種操作,並且支援XPATH查詢,以及部分的支援XSLT轉換等功能。Libxml2的下載地址是http://xmlsoft.org/,完全版的庫是開源的,並且帶有例子程式和說明文件。最好將這個庫
Linux C語言程式設計(上篇) | gcc的使用
嵌入式軟體開發主要使用C語言開發,編譯過程稱為交叉編譯 —— 在PC機上編譯出可以在嵌入式處理器上執行的程式,在真正進入嵌入式開發前,先來了解下如何使用gcc+make編譯C語言工程,如何用gdb除錯工程~ 1.C程式設計流程 1.1.編輯原始檔(.c) 使用文字編輯器(比如vi
浙大版《C語言程式設計(第3版)》題目集 - 習題11-5 指定位置輸出字串(20 分)
題目連結:點選開啟連結 題目大意:略。 解題思路:略。 AC 程式碼 char *match( char *s, char ch1, char ch2 ) { char *p=s, *h; int fst=1,
浙大版《C語言程式設計(第3版)》題目集 - 習題11-7 奇數值結點連結串列(20 分)
題目連結:點選開啟連結 題目大意:略。 解題思路:題目說刪除了,其實可以轉化為再搞一個獲取奇數時的做法來做偶數的情況,最後把地址賦值給L,這樣思路就簡單許多~。還有這裡帶兩個星號的L,其實多了一個星號是因為傳參時,傳進去的是指標變數的地址(此地址非內容
《C語言程式設計(第二版新版)》第一章習題解答(部分)
1-20 //My solution:先將輸入字串儲存至陣列,將其detab後存入另一陣列,然後列印該陣列 #include <stdio.h> #define MAXLINE 100 #define TABSIZE 8 #define TAB '\t' in
浙大版《C語言程式設計(第3版)》題目集(函式題)練習5-1
練習5-1 求m到n之和(10 分) 本題要求實現一個計算m~n(m 函式介面定義: int sum( int m, int n ); 其中m和n是使用者傳入的引數,保證有m < n。
C語言程式設計(圖形庫應用)--導航
** 1.引言 ** 最近又開始研究以前高中接觸的C++圖形庫(easyx),準備在此基礎上進行一些有趣的例項開發並做一些C語言程式設計教程。 2.開發環境 Visual Studio C