當前位置:首頁 » 編程語言 » c語言語錄

c語言語錄

發布時間: 2022-06-08 01:33:35

c語言語句種類有哪些

C語句可分為以下五類:


1 表達式語句;

2 函數調用語句;

3 控制語句;


4 復合語句;

5 空語句。

② 最基本的C語言語句是什麼語句

B、表達式語句

C語句可分為五類:1.表達式語句;2.函數調用語句;3.控制語句;4.復合語句;5.空語句。
其中最基本的語句是表達式語句,因為僅僅用表達式語句也能寫出簡單程序。

賦值語句屬於表達式語句中的一種
循環語句屬於控制語句中的一種

③ C語言的9種控制語句是什麼啊

C語言9種控制語句

①if( )~else 條件語句

②for( )~ 循環語句

③while( )~ 循環語句

④do~while( ) 循環語句

⑤continue 結束本次循環語句

⑥break 中止執行switch或循環語句

⑦switch 多分支選擇語句

⑧goto 轉向語句

⑨return 從函數返回語句

(3)c語言語錄擴展閱讀

基本特性

1、高級語言:它是把高級語言的基本結構和語句與低級語言的實用性結合起來的工作單元。

2、結構式語言:結構式語言的顯著特點是代碼及數據的分隔化,即程序的各個部分除了必要的信息交流外彼此獨立。這種結構化方式可使程序層次清晰,便於使用、維護以及調試。C 語言是以函數形式提供給用戶的,這些函數可方便的調用,並具有多種循環、條件語句控製程序流向,從而使程序完全結構化。

3、代碼級別的跨平台:由於標準的存在,使得幾乎同樣的C代碼可用於多種操作系統,如Windows、DOS、UNIX等等;也適用於多種機型。C語言對編寫需要進行硬體操作的場合,優於其它高級語言。

4、使用指針:可以直接進行靠近硬體的操作,但是C的指針操作不做保護,也給它帶來了很多不安全的因素。C++在這方面做了改進,在保留了指針操作的同時又增強了安全性,受到了一些用戶的支持,但是,由於這些改進增加語言的復雜度,也為另一部分所詬病。java則吸取了C++的教訓,取消了指針操作,也取消了C++改進中一些備受爭議的地方,在安全性和適合性方面均取得良好的效果,但其本身解釋在虛擬機中運行,運行效率低於C++/C。一般而言,C,C++,java被視為同一系的語言,它們長期占據著程序使用榜的前三名。

參考資料

C語言--網路

④ C語言編程的常用語句及其作用

C語言控制語句①條件語句:if—else語句
②開關語句:switch語句
⑧當循環語句:while語句
④直到循環語句:do—while語句
⑤計數循環語句:for·語句
⑥中止本次循環語句:continue語句
⑦中止整個循環語句:break語句
⑧函數返回語句:return語句
⑨無條件轉移語句:goto語句 C語言的關鍵字共有32個,根據關鍵字的作用,可分其為數據類型關鍵字、控制語句關鍵字、存儲類型關鍵字和其它關鍵字四類。

1 數據類型關鍵字(12個): (1) char :聲明字元型變數或函數
(2) double :聲明雙精度變數或函數
(3) enum :聲明枚舉類型
(4) float:聲明浮點型變數或函數
(5) int: 聲明整型變數或函數
(6) long :聲明長整型變數或函數
(7) short :聲明短整型變數或函數
(8) signed:聲明有符號類型變數或函數
(9) struct:聲明結構體變數或函數
(10) union:聲明共用體(聯合)數據類型
(11) unsigned:聲明無符號類型變數或函數
(12) void :聲明函數無返回值或無參數,聲明無類型指針(基本上就這三個作用)

2控制語句關鍵字(12個): A循環語句
(1) for:一種循環語句(可意會不可言傳)
(2) do :循環語句的循環體
(3) while :循環語句的循環條件
(4) break:跳出當前循環
(5) continue:結束當前循環,開始下一輪循環
B條件語句
(1)if: 條件語句
(2)else :條件語句否定分支(與 if 連用)
(3)goto:無條件跳轉語句
C開關語句
(1)switch :用於開關語句
(2)case:開關語句分支
(3)default:開關語句中的「其他」分支
D返回語句
return :子程序返回語句(可以帶參數,也看不帶參數)

3 存儲類型關鍵字(4個) (1)auto :聲明自動變數 一般不使用
(2)extern:聲明變數是在其他文件正聲明(也可以看做是引用變數)
(3)register:聲明積存器變數
(4)static :聲明靜態變數 4 其它關鍵字(4個): (1)const :聲明只讀變數
(2)sizeof:計算數據類型長度
(3)typedef:用以給數據類型取別名(當然還有其他作用
(4)volatile:說明變數在程序執行中可被隱含地改變

⑤ c語言之基本語句

"%4d"意思是輸出數字為十進制,佔4格
"%4o"意思是輸出數字為八進制,佔4格
"%4x"意思是輸出數字為十六進制,佔4格,如果"x"變為"X",結果是"3F"
第二題中因為float
*y:字元y是指針

⑥ C語言所有語句格式

循環結構是程序中一種很重要的結構。其特點是, 在給定條件成立時,反復執行某程序段,直到條件不成立為止。 給定的條件稱為循環條件,反復執行的程序段稱為循環體。 C語言提供了多種循環語句,可以組成各種不同形式的循環結構。

while語句

while語句的一般形式為: while(表達式)語句; 其中表達式是循環條件,語句為循環體。
while語句的語義是:計算表達式的值,當值為真(非0)時, 執行循環體語句。其執行過程可用圖3—4表示。 統計從鍵盤輸入一行字元的個數。
#include <stdio.h>
void main(){
int n=0;
printf("input a string:\n");
while(getchar()!='\n') n++;
printf("%d",n);
}
本常式序中的循環條件為getchar()!='\n',其意義是, 只要從鍵盤輸入的字元不是回車就繼續循環。循環體n++完成對輸入字元個數計數。從而程序實現了對輸入一行字元的字元個數計數。
使用while語句應注意以下幾點:
1.while語句中的表達式一般是關系表達或邏輯表達式,只要表達式的值為真(非0)即可繼續循環。
void main(){
int a=0,n;
printf("\n input n: ");
scanf("%d",&n);
while (n--)
printf("%d ",a++*2);
}
本常式序將執行n次循環,每執行一次,n值減1。循環體輸出表達式a++*2的值。該表達式等效於(a*2;a++)
2.循環體如包括有一個以上的語句,則必須用{}括起來, 組成復合語句。
3.應注意循環條件的選擇以避免死循環。
void main(){
int a,n=0;
while(a=5)
printf("%d ",n++);
}
本例中while語句的循環條件為賦值表達式a=5, 因此該表達式的值永遠為真,而循環體中又沒有其它中止循環的手段, 因此該循環將無休止地進行下去,形成死循環。4.允許while語句的循環體又是while語句,從而形成雙重循環。

do-while語句

do-while語句的一般形式為:
do
語句;
while(表達式);
其中語句是循環體,表達式是循環條件。
do-while語句的語義是:
先執行循環體語句一次, 再判別表達式的值,若為真(非0)則繼續循環,否則終止循環。
do-while語句和while語句的區別在於do-while是先執行後判斷,因此do-while至少要執行一次循環體。而while是先判斷後執行,如果條件不滿足,則一次循環體語句也不執行。
while語句和do-while語句一般都可以相互改寫。
void main(){
int a=0,n;
printf("\n input n: ");
scanf("%d",&n);
do printf("%d ",a++*2);
while (--n);
}

在本例中,循環條件改為--n,否則將多執行一次循環。這是由於先執行後判斷而造成的。
對於do-while語句還應注意以下幾點:
1.在if語句,while語句中, 表達式後面都不能加分號, 而在 do-while語句的表達式後面則必須加分號。
2.do-while語句也可以組成多重循環,而且也可以和while語句相互嵌套。
3.在do和while之間的循環體由多個語句組成時,也必須用{}括起來組成一個復合語句。
4.do-while和while語句相互替換時,要注意修改循環控制條件。

⑦ C語言程序中常用的語句…要比較全一點的

B.插入排序:

思路:當前a[1]..a[i-1]已排好序了,現要插入a[i]使a[1]..a[i]有序。
procere insert_sort;
var i,j:integer;
begin
for i:=2 to n do begin
a[0]:=a[i];
j:=i-1;
while a[0]a[j] then swap(a[i],a[j]);
end;

D. 冒泡排序
procere bubble_sort;
var i,j,k:integer;
begin
for i:=1 to n-1 do
for j:=n downto i+1 do
if a[j]r) or (a[i]<=a[j])) {滿足取左邊序列當前元素的要求}
then begin
tmp[t]:=a[i]; inc(i);
end
else begin
tmp[t]:=a[j];inc(j);
end;
inc(t);
end;
for i:=p to r do a[i]:=tmp[i];
end;{merge}

procere merge_sort(var a:listtype; p,r: integer); {合並排序a[p..r]}
var q:integer;
begin
if p<>r then begin
q:=(p+r-1) div 2;
merge_sort (a,p,q);
merge_sort (a,q+1,r);
merge (a,p,q,r);
end;
end;
{main}
begin
merge_sort(a,1,n);
end.

G.基數排序
思想:對每個元素按從低位到高位對每一位進行一次排序

五、高精度計算

高精度數的定義:
type
hp=array[1..maxlen] of integer;

1.高精度加法

procere plus ( a,b:hp; var c:hp);
var i,len:integer;
begin
fillchar(c,sizeof(c),0);
if a[0]>b[0] then len:=a[0] else len:=b[0];
for i:=1 to len do begin
inc(c[i],a[i]+b[i]);
if c[i]>10 then begin dec(c[i],10); inc(c[i+1]); end; {進位}
end;
if c[len+1]>0 then inc(len);
c[0]:=len;
end;{plus}

2.高精度減法
procere substract(a,b:hp;var c:hp);
var i,len:integer;
begin
fillchar(c,sizeof(c),0);
if a[0]>b[0] then len:=a[0] else len:=b[0];
for i:=1 to len do begin
inc(c[i],a[i]-b[i]);
if c[i]<0 then begin inc(c[i],10);dec(c[i+1]); end;
while (len>1) and (c[len]=0) do dec(len);
c[0]:=len;
end;

3.高精度乘以低精度

procere multiply(a:hp;b:longint;var c:hp);
var i,len:integer;
begin
fillchar(c,sizeof(c),0);
len:=a[0];
for i:=1 to len do begin
inc(c[i],a[i]*b);
inc(c[i+1],(a[i]*b) div 10);
c[i]:=c[i] mod 10;
end;
inc(len);
while (c[len]>=10) do begin {處理最高位的進位}
c[len+1]:=c[len] div 10;
c[len]:=c[len] mod 10;
inc(len);
end;
while (len>1) and (c[len]=0) do dec(len); {若不需進位則調整len}
c[0]:=len;
end;{multiply}

4.高精度乘以高精度

procere high_multiply(a,b:hp; var c:hp}
var i,j,len:integer;
begin
fillchar(c,sizeof(c),0);
for i:=1 to a[0] do
for j:=1 to b[0] do begin
inc(c[i+j-1],a[i]*b[j]);
inc(c[i+j],c[i+j-1] div 10);
c[i+j-1]:=c[i+j-1] mod 10;
end;
len:=a[0]+b[0]+1;
while (len>1) and (c[len]=0) do dec(len);
c[0]:=len;
end;

5.高精度除以低精度

procere devide(a:hp;b:longint; var c:hp; var d:longint);
{c:=a div b; d:= a mod b}
var i,len:integer;
begin
fillchar(c,sizeof(c),0);
len:=a[0]; d:=0;
for i:=len downto 1 do begin
d:=d*10+a[i];
c[i]:=d div b;
d:=d mod b;
end;
while (len>1) and (c[len]=0) then dec(len);
c[0]:=len;
end;

6.高精度除以高精度

procere high_devide(a,b:hp; var c,d:hp);
var
i,len:integer;
begin
fillchar(c,sizeof(c),0);
fillchar(d,sizeof(d),0);
len:=a[0];d[0]:=1;
for i:=len downto 1 do begin
multiply(d,10,d);
d[1]:=a[i];
while(compare(d,b)>=0) do {即d>=b}
begin
Subtract(d,b,d);
inc(c[i]);
end;
end;
while(len>1)and(c.s[len]=0) do dec(len);
c.len:=len;
end;

六、 樹的遍歷

1.已知前序中序求後序

procere Solve(pre,mid:string);
var i:integer;
begin
if (pre='''') or (mid='''') then exit;
i:=pos(pre[1],mid);
solve((pre,2,i),(mid,1,i-1));
solve((pre,i+1,length(pre)-i),(mid,i+1,length(mid)-i));
post:=post+pre[1]; {加上根,遞歸結束後post即為後序遍歷}
end;

2.已知中序後序求前序

procere Solve(mid,post:string);
var i:integer;
begin
if (mid='''') or (post='''') then exit;
i:=pos(post[length(post)],mid);
pre:=pre+post[length(post)]; {加上根,遞歸結束後pre即為前序遍歷}
solve((mid,1,I-1),(post,1,I-1));
solve((mid,I+1,length(mid)-I),(post,I,length(post)-i));
end;

3.已知前序後序求中序的一種

function ok(s1,s2:string):boolean;
var i,l:integer; p:boolean;
begin
ok:=true;
l:=length(s1);
for i:=1 to l do begin
p:=false;
for j:=1 to l do
if s1[i]=s2[j] then p:=true;
if not p then begin ok:=false;exit;end;
end;
end;

procere solve(pre,post:string);
var i:integer;
begin
if (pre='''') or (post='''') then exit;
i:=0;
repeat
inc(i);
until ok((pre,2,i),(post,1,i));
solve((pre,2,i),(post,1,i));
midstr:=midstr+pre[1];
solve((pre,i+2,length(pre)-i-1),(post,i+1,length(post)-i-1));
end;

七 進制轉換

1.任意正整數進制間的互化

除n取余

2.實數任意正整數進制間的互化
乘n取整

3.負數進制:
設計一個程序,讀入一個十進制數的基數和一個負進制數的基數,並將此十進制數轉換為此負進制下的數:-R∈{-2,-3,-4,....-20}

八 全排列與組合的生成

1.排列的生成:(1..n)
procere solve(dep:integer);
var
i:integer;
begin
if dep=n+1 then begin writeln(s);exit; end;
for i:=1 to n do
if not used[i] then begin
s:=s+chr(i+ord(''0''));used[i]:=true;
solve(dep+1);
s:=(s,1,length(s)-1); used[i]:=false;
end;
end;

2.組合的生成(1..n中選取k個數的所有方案)
procere solve(dep,pre:integer);
var
i:integer;
begin
if dep=k+1 then begin writeln(s);exit; end;
for i:=1 to n do
if (not used[i]) and (i>pre) then begin
s:=s+chr(i+ord(''0''));used[i]:=true;
solve(dep+1,i);
s:=(s,1,length(s)-1); used[i]:=false;
end;
end;

九.查找演算法

1.折半查找

function binsearch(k:keytype):integer;
var low,hig,mid:integer;
begin
low:=1;hig:=n;
mid:=(low+hig) div 2;
while (a[mid].key<>k) and (low<=hig) do begin
if a[mid].key>k then hig:=mid-1
else low:=mid+1;
mid:=(low+hig) div 2;
end;
if low>hig then mid:=0;
binsearch:=mid;
end;

2.樹形查找

二叉排序樹:每個結點的值都大於其左子樹任一結點的值而小於其右子樹任一結點的值。
查找
function treesrh(k:keytype):pointer;
var q:pointer;
begin
q:=root;
while (q<>nil) and (q^.key<>k) do
if kgoal then begin {若未移到目標}
Move(k-1,6-now-goal); {剩下的先移到沒用的柱上}
Writeln(k moved from now to goal);
H[goal,h[goal,0]+1]:=h[now,nowp]; h[now,nowp]:=0;
Inc(h[goal,0]); dec(h[now,0]);
Move(k-1,goal); {剩下的移到目標上}
End;

十二、DFS框架

NOIP2001 數的劃分

procere work(dep,pre,s:longint); {入口為work(1,1,n)}
{dep為當前試放的第dep個數,pre為前一次試放的數,s為當前剩餘可分的總數}
var j:longint;
begin
if dep=n then begin
if s>=pre then inc(r); exit;
end;
for j:=pre to s div 2 do work(dep+1,j,s-j);
end;
類似:
procere try(dep:integer);
var i:integer;
begin
if dep=k then begin
if tot>=a[dep-1] then inc(sum);
exit; end;
for i:=a[dep-1] to tot div 2 do begin
a[dep]:=i; dec(tot,i);
try(dep+1);
inc(tot,i);
end;
end;{try}

十三、BFS框架

IOI94 房間問題
head:=1; tail:=0;
while tail=1) and (I<=L.len) then
while j<I do begin p:=p^.next; inc(j); end;
loc:=p;
end;

2.單鏈表的插入操作

procere insert(L:linklist; I:integer; x:datatype);
var p,q:pointer;
begin
p:=loc(L,I);
new(q);
q^.data:=x;
q^.next:=p^.next;
p^.next:=q;
inc(L.len);
end;

3.單鏈表的刪除操作

procere delete(L:linklist; I:integer);
var p,q:pointer;
begin
p:=loc(L,I-1);
q:=p^.next;
p^.next:=q^.next;
dispose(q);
dec(L.len);
end;

4.雙鏈表的插入操作(插入新結點q)

p:=loc(L,I);
new(q);
q^.data:=x;
q^.pre:=p;
q^.next:=p^.next;
p^.next:=q;
q^.next^.pre:=q;

5.雙鏈表的刪除操作

p:=loc(L,I); {p為要刪除的結點}
p^.pre^.next:=p^.next;
p^.next^.pre:=p^.pre;
dispose(p);

⑧ c語言語句有哪些

C語句可分為以下五類: 1.表達式語句; 2.函數調用語句; 3.控制語句; 4.復合語句; 5.空語句。
1.表達式語句
表達式語句由表達式加上分號「;」組成。 其一般形式為: 表達式;執行表達式語句就是計算表達式的值。 例如: x=y+z;a=520; 賦值語句; y+z;加法運算語句,但計算結果不能保留,無實際意義; i++; 自增1語句,i值增1。 i++; 是先運算i後再加1。 ++i; 是先把i值增1後運算。
編輯本段2.函數調用語句
由函數名、實際參數加上分號「;」組成。 其一般形式為: 函數名(實際參數表) ; 執行函數語句就是調用函數體並把實際參數賦予函數定義中的形式參數,然後執行被調函數體中的語句,求取函數值。 調用庫函數,輸出字元串。
編輯本段3.控制語句
控制語句用於控製程序的流程, 以實現程序的各種結構方式。 它們由特定的語句定義符組成。C語言有九種控制語句。 可分成以下三類: (1). 條件判斷語句 if語句、switch語句; (2) .循環執行語句 do while語句、while語句、for語句; (3). 轉向語句 break語句、goto語句(此語句盡量少用,因為這不利結構化程序設計,濫用它會使程序流程無規律、可讀性差)、continue語句、return語句。
編輯本段條件判斷
int a,b; if(x>y) printf("x,\n"); else printf("y,\n");
編輯本段4.復合語句
把多個語句用括弧{}括起來組成的一個語句稱復合語句。 在程序中應把復合語句看成是單條語句,而不是多條語句,例如 { x=y+z; a=b+c; printf(「%d%d」,x,a); } 是一條復合語句。復合語句內的各條語句都必須以分號「;」結尾;此外,在括弧「}」外不能加分號。
編輯本段5.空語句
只有分號「;」組成的語句稱為空語句。 空語句是什麼也不執行的語句。在程序中空語句可用來作空循環體。 例如 while(getchar()!='\n'); 本語句的功能是,只要從鍵盤輸入的字元不是回車則重新輸入。這里的循環體為空語句。

⑨ C語言if語錄的用法

1.if語句的一般格式

if(表達式)

{語句組1;}

[else

{語句組2;}
]
(1)if語句中的「表達式」必須用「(」和「)」括起來。
(2)else子句(可選)是if語句的一部分,必須與if配對使用,不能單獨使用。
(3)當if和else下面的語句組,僅由一條語句構成時,也可不使用復合語句形式(即去掉花括弧)。
2.if語句的執行過程
(1)預設else子句時
當「表達式」的值不等於0(即判定為「邏輯真」)時,則執行語句組1,否則直接轉向執行下一條。
(2)指定else子句時
當「表達式」的值不等於0(即判定為「邏輯真」)時,則執行語句組1,然後轉向下一條語句;否則,執行語句組2。如圖4-1(b)所示。
3.if語句的嵌套與嵌套匹配原則
if語句允許嵌套。所謂if語句的嵌套是指,在「語句組1」或(和)「語句組2」中,又包含有if語句的情況。
if語句嵌套時,else子句與if的匹配原則:與在它上面、距它最近、且尚未匹配的if配對。
為明確匹配關系,避免匹配錯誤,強烈建議:將內嵌的if語句,一律用花括弧括起來。

熱點內容
我的世界伺服器如何挖 發布:2024-05-21 07:39:12 瀏覽:793
路游器怎麼改密碼 發布:2024-05-21 07:36:10 瀏覽:26
悅卷通安卓版叫什麼 發布:2024-05-21 07:27:07 瀏覽:980
聯盟網站源碼 發布:2024-05-21 06:56:57 瀏覽:978
linuxshell入門 發布:2024-05-21 06:44:26 瀏覽:757
如何用手機設置qq郵箱密碼 發布:2024-05-21 06:42:56 瀏覽:61
映像壓縮 發布:2024-05-21 05:46:53 瀏覽:726
小葫蘆直播助手伺服器地址 發布:2024-05-21 05:46:51 瀏覽:969
遨遊緩存視頻 發布:2024-05-21 05:46:47 瀏覽:784
家用電腦能裝伺服器 發布:2024-05-21 05:45:56 瀏覽:437