1.第一個 C 程式—Hello World
#include<stdio.h>
#include<stdlib.h>
int main(){
printf("***************\n");
printf("Hello world\n");
printf("哈囉! 您好~\n");
system("pause");
return 0;
}
2.撰寫一個程式,使用星號印出下列圖形(如交通號誌)
#include<stdio.h>
#include<stdlib.h>
int main(){
printf("Hello World\n");
printf("哈囉! 您好~\n");
printf("********* *** * *\n");
printf("* * * * *** * *\n");
printf("* * * * ***** * *\n");
printf("* * * * * * *\n");
printf("* * * * * * *\n");
printf("* * * * * * *\n");
printf("* * * * * * *\n");
printf("* * * * * * *\n");
printf("********* *** * *\n");
system("pause");
return 0;
}
3. 使用八行 printf 敍述式顯示一個西洋棋的棋盤,然後嘗試用
更少的敍述顯示相同的圖案。
#include<stdio.h>
#include<stdlib.h>
int main() {
printf("Hello World\n");
printf("哈囉! 您好~\n");
printf("With eight printf() statement:\n");
printf("* * * * * * * *\n");
printf(" * * * * * * * *\n");
printf("* * * * * * * *\n");
printf(" * * * * * * * *\n");
printf("* * * * * * * *\n");
printf(" * * * * * * * *\n");
printf("* * * * * * * *\n");
printf(" * * * * * * * *\n");
printf("Now with one printf() statement:\n");
printf("* * * * * * * *\n * * * * * * * *\n* * * * * * * *\n * * * * * * * *\n* * * * * * * *\n * * * * * * * *\n* * * * * * * *\n * * * * * * * *\n");
system("pause");
return 0;
}
4. 在 C 語言的內部,是使用整數來表示每個字元的。這一組
字元以及電腦用來對慼這組字元的整數,就稱為電腦字元集
(character set)。你可以印出代表大寫 A 的整數。例如,執行以下
敍述式 printf(“%d”, ‘A’); 寫一個 C 程式,印出代表某些大寫字
母、小寫字母、數字和特殊符號的整數。你至少要能印出代表下
列字元的整數:A B C a b c 0 1 2 3 * + / 以及空白字元
#include<stdio.h>
#include<stdlib.h>
int main() {
printf("Hello World\n");
printf("哈囉! 您好~\n");
printf("A's integer equivalent is %d\n",'A');
printf("B's integer equivalent is %d\n",'B');
printf("C's integer equivalent is %d\n",'C');
printf("D's integer equivalent is %d\n",'D');
printf("E's integer equivalent is %d\n",'E');
printf("F's integer equivalent is %d\n",'F');
printf("G's integer equivalent is %d\n",'G');
printf("H's integer equivalent is %d\n",'H');
printf("I's integer equivalent is %d\n",'I');
printf("J's integer equivalent is %d\n",'J');
printf("K's integer equivalent is %d\n",'K');
printf("L's integer equivalent is %d\n",'L');
printf("M's integer equivalent is %d\n",'M');
printf("N's integer equivalent is %d\n",'N');
printf("O's integer equivalent is %d\n",'O');
printf("P's integer equivalent is %d\n",'P');
printf("Q's integer equivalent is %d\n",'Q');
printf("R's integer equivalent is %d\n",'R');
printf("S's integer equivalent is %d\n",'S');
printf("T's integer equivalent is %d\n",'T');
printf("U's integer equivalent is %d\n",'U');
printf("V's integer equivalent is %d\n",'V');
printf("W's integer equivalent is %d\n",'W');
printf("X's integer equivalent is %d\n",'X');
printf("Y's integer equivalent is %d\n",'Y');
printf("Z's integer equivalent is %d\n",'Z');
printf("['s integer equivalent is %d\n",'[');
printf("]'s integer equivalent is %d\n",']');
printf("^'s integer equivalent is %d\n",'^');
printf("_'s integer equivalent is %d\n",'_');
printf("a's integer equivalent is %d\n",'a');
printf("b's integer equivalent is %d\n",'b');
printf("c's integer equivalent is %d\n",'c');
printf("d's integer equivalent is %d\n",'d');
printf("e's integer equivalent is %d\n",'e');
printf("f's integer equivalent is %d\n",'f');
printf("g's integer equivalent is %d\n",'g');
printf("h's integer equivalent is %d\n",'h');
printf("i's integer equivalent is %d\n",'i');
printf("j's integer equivalent is %d\n",'j');
printf("k's integer equivalent is %d\n",'k');
printf("l's integer equivalent is %d\n",'l');
printf("m's integer equivalent is %d\n",'m');
printf("n's integer equivalent is %d\n",'n');
printf("o's integer equivalent is %d\n",'o');
printf("p's integer equivalent is %d\n",'p');
printf("q's integer equivalent is %d\n",'q');
printf("r's integer equivalent is %d\n",'r');
printf("s's integer equivalent is %d\n",'s');
printf("t's integer equivalent is %d\n",'t');
printf("u's integer equivalent is %d\n",'u');
printf("v's integer equivalent is %d\n",'v');
printf("w's integer equivalent is %d\n",'w');
printf("x's integer equivalent is %d\n",'x');
printf("y's integer equivalent is %d\n",'y');
printf("z's integer equivalent is %d\n",'z');
printf("{'s integer equivalent is %d\n",'{');
printf("|'s integer equivalent is %d\n",'|');
printf("}'s integer equivalent is %d\n",'}');
printf("~'s integer equivalent is %d\n",'~');
printf("!'s integer equivalent is %d\n",'!');
printf("#'s integer equivalent is %d\n",'#');
printf("$'s integer equivalent is %d\n",'$');
printf("%'s integer equivalent is %d\n",'%');
printf("&'s integer equivalent is %d\n",'&');
printf("('s integer equivalent is %d\n",'(');
printf(")'s integer equivalent is %d\n",')');
printf("*'s integer equivalent is %d\n",'*');
printf("+'s integer equivalent is %d\n",'+');
printf(",'s integer equivalent is %d\n",',');
printf("-'s integer equivalent is %d\n",'-');
printf(".'s integer equivalent is %d\n",'.');
printf("/'s integer equivalent is %d\n",'/');
printf("0's integer equivalent is %d\n",'0');
printf("1's integer equivalent is %d\n",'1');
printf("2's integer equivalent is %d\n",'2');
printf("3's integer equivalent is %d\n",'3');
printf("4's integer equivalent is %d\n",'4');
printf("5's integer equivalent is %d\n",'5');
printf("6's integer equivalent is %d\n",'6');
printf("7's integer equivalent is %d\n",'7');
printf("8's integer equivalent is %d\n",'8');
printf("9's integer equivalent is %d\n",'9');
printf(":'s integer equivalent is %d\n",':');
printf(";'s integer equivalent is %d\n",';');
printf("<'s integer equivalent is %d\n",'<');
printf(">'s integer equivalent is %d\n",'>');
printf("?'s integer equivalent is %d\n",'?');
printf("@'s integer equivalent is %d\n",'@');
printf("The blank character's integer equivalent is %d\n",' ');
system("use");
return 0;
}
5. 王先生是在一家資訊公司上班, 他是個朝九晚五的上班族,
也就是說王先生每天都是從九點準時上班, 一直到傍晚五點鐘下
班。試問假如王先生中午時刻是不休息的, 那他一天總共要工作
多少秒。(提示: C 語言的+、-、*、/ 運算子分別代表加、減、
乘、除)
#include<stdio.h>
#include<stdlib.h>
int main(){
printf("Hello World\n");
printf("哈囉! 您好~\n");
int sec;
int min;
int hour;
int time;
sec=60;
min=60;
hour=8;
time=sec*min*hour;
printf("time is number of %d\n",time);
printf("傍晚五點換算24小時制為17:00,早上九點換算24小時制為9:00\n");
printf("由17:00-9:00=8:00,共8小時,一小時60分鐘,一分鐘60秒\n");
printf("8小時計算為,8*60*60=8*3600=28800秒\n");
system("pause");
return 0;
}
6. 假設您現在修的科目有計概、C 語言、微積分、英文、電子
學 , 試著將它們取適當的變數名稱, 並在宣告時順便給多初值, 請計算這五科的總和及平均分數為何?
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char** argv) {
int computer_concepts=99,
C_language=88,
calculus=77,
english=66,
electronics=55;
printf("計概=%d\nC語言=%d\n微積分=%d\n英文=%d\n電子學=%d\n",computer_concepts,C_language,calculus,english,electronics);
printf("總分:%d",computer_concepts+C_language+calculus+english+electronics);
printf("平均:%d",(computer_concepts+C_language+calculus+english+electronics)/5);
system("pause");
return 0;
}
沒有留言:
張貼留言