資源描述:
《C語(yǔ)言其實(shí)很簡(jiǎn)單教學(xué)全套課件C語(yǔ)言其實(shí)很簡(jiǎn)單教學(xué)課件 作者 源代碼.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、【程序例1.1】C語(yǔ)言程序的簡(jiǎn)單實(shí)例。main(){inta,b,c;a=10;b=20;c=a+b;printf("%d",c);}main(){inta,b,c;a=10;b=20;c=a+b;printf("%d",c);}main(){inta,b,c;a=10;/*小明有10支鉛筆*/b=20;/*小紅有20支鉛筆*/c=a+b;/*求小明和小紅共有幾支鉛筆*/printf("%d",c);}/*注釋①*/main(/*注釋②*/){/*注釋③*/int/*注釋④*/a,b,c;a=10;b=20;/*注釋⑤的第一行注釋⑤的第二行*/c=
2、a+b;/*注釋⑥*//*注釋⑦*/printf("%d",/*注釋⑧*/c);}main(){inta,b,c;/*a=10;b=20;*/c=a+b;printf("%d",c);}【程序例2.1】用printf輸出字符串的功能,輸出圖2.9所示的“穿心”圖形。main(){printf("****");printf("****");printf("*★*★*");printf("*★*");printf(">>>------Iloveyou!------>");printf("**");printf("*★*");
3、printf("**");printf("**");printf("*");}【程序例2.2】數(shù)據(jù)類型的自動(dòng)轉(zhuǎn)換。main(){doublepai=3.14;ints,r=2;s=r*r*pai;printf("s=%d",s);}【程序例2.3】取一個(gè)整數(shù)的個(gè)位、十位、百位、千位。#includemain(){intn=1234;intge,shi,bai,qian;ge=n%10;shi=n/10%10;bai=n/100%10;qian=n/1000;/*或?qū)憺閝ian=n/1000%10;*/printf(
4、"%d",ge);printf("%d",shi);printf("%d",bai);printf("%d",qian);}【程序例3.1】輸出單個(gè)字符。#includemain(){chara='V',b='C';putchar(a);putchar(b);putchar(a);putchar(b-1);putchar('');putchar(a);putchar(b);}【程序例3.2】輸入單個(gè)字符。#includemain(){charc;c=getchar();putchar(c);}
5、【程序例3.3】多次調(diào)用getchar輸入多個(gè)字符。#includemain(){charc1,c2,c3,c4,c5;c1=getchar();c2=getchar();c3=getchar();c4=getchar();c5=getchar();putchar(c1);putchar(c2);putchar(c3);putchar(c4);putchar(c5);}main(){inta=123;printf("%d",a);/*輸出123*/printf("%2d",a);/*輸出123(劃定2格不夠,沖破限制原樣輸
6、出)*/printf("%4d,",a);/*輸出123,(劃定4格,前補(bǔ)1空格右對(duì)齊)*/printf("%-4d,",a);/*輸出123,(劃定4格,后補(bǔ)1空格左對(duì)齊)*/}main(){floatb=1.238;printf("%f",b);/*輸出1.238000*/printf("%2f",b);/*輸出1.238000,沖破2格限制*/printf("%6.2f,",b);/*輸出1.24,前補(bǔ)2空格,共占6格*/printf("%-6.2f,",b);/*輸出1.24,后補(bǔ)2空格,共占6格*/printf("
7、%6.0f,",b);/*輸出1,前補(bǔ)5空格*/}【程序例3.4】從鍵盤輸入3個(gè)整數(shù),分別存入三個(gè)變量a、b、c中。main(){inta,b,c;printf("inputa,b,c");scanf("%d%d%d",&a,&b,&c);printf("a=%d,b=%d,c=%d",a,b,c);}【程序例3.5】酒店接待處的歡迎程序:請(qǐng)用戶輸入自己的房間號(hào),然后給出歡迎信息。#includemain(){introom;printf("歡迎光臨本酒店!");printf("請(qǐng)輸入您的房間號(hào):");scanf(
8、"%d",&room);printf("您的房間號(hào)是:%d",room);printf("您好!房間%d的客人!"