2016年1月14日 星期四

在Android手機,平板玩C語言

/*在Android手機,平板玩C語言,

請下載安裝Cppdroid,即可編譯執行C語言,

1.長按此區然後複製

2.將此程式貼在Cppdroid程式區

3.按儲存,編譯,執行即可*/

/*列印出 Hello, World! 的C語言*/

‪#‎include ‬<stdio.h>

int main()

{

printf("Hello, World! \n");

return 0;

}

/*Android系統C語言的免費代碼編譯器介紹

http://seelab.zjsu.edu.cn:4000/node/4649

*/

/*斜線和星號內的文字會被忽略,不會影響程式運作*/

2015年12月30日 星期三

國小第一堂數學課

各位小朋友大家好!今天你們國小的第一堂數學課上的是計算a+b=?

請大家輸入下列程式,然後計算兩個數的合。

#‎include ‬<stdio.h>

int main()

{

int a, b, c;

printf("請輸入兩個整數,然後它會幫你相加。\n");

scanf("%d%d",&a,&b);

c = a + b;

printf("相加的答案 = %d\n",c);

return 0;

}

p.s.各位小朋友,我們的老祖宗曾經用手指算數學,也用過算盤,還有那個小小的電子計算機算的,甚至用什麼Apple II 算的,這些都落伍了!我們今天是用最快速的 C 語言來計算,在這變動的世界環境裡,隨時改變程式設計,才可以適應不同的需求。

查查看2016是否為閏年(leap year)?

‪#include <stdio.h>

int main()

{

int year;

printf("Enter a year to check if it is a leap year\n");

scanf("%d", &year);

if ( year%400 == 0)

printf("%d is a leap year.\n", year);

else if ( year%100 == 0)

printf("%d is not a leap year.\n", year);

else if ( year%4 == 0 )

printf("%d is a leap year.\n", year);

else

printf("%d is not a leap year.\n", year);

return 0;

}

p.s. 在Windows系統玩C語言

2015年8月4日 星期二

用 || (或) 來判斷英文字母是否為母音

#include <stdio.h>

int main()

{

char ch;

printf("Enter a character\n");

scanf("%c", &ch);

if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch =='o' || ch=='O' || ch == 'u' || ch == 'U') printf("%c is a vowel.\n", ch);

else

printf("%c is not a vowel.\n", ch);

return 0;

}

p.s.每次執行程式的時候,只能判斷一次,不能重複判斷

首頁

2015年7月19日 星期日

列印字串 Hello World! 的解說

#‎include ‬<stdio.h> //#include:引入stdio.h檔案     stdio.h:系統的引入檔

int main() //int : 宣告其回傳值為整數    main : 函數(本程式的主要函數)

{

printf("Hello, World! \n"); //printf:輸出到螢幕,列印出Hello world!   \n : 換行字元

return 0; //將整數0回傳給呼叫main的函數

}

首頁

2015年7月9日 星期四

一次做完加減乘除

#include <stdio.h>

int main()

{

int first, second, add, subtract, multiply;

float divide;

printf("Enter two integers\n");

scanf("%d%d", &first, &second);

add = first + second;

subtract = first - second;

multiply = first * second;

divide = first / (float)second; //typecasting

printf("Sum = %d\n",add);

printf("Difference = %d\n",subtract);

printf("Multiplication = %d\n",multiply);

printf("Division = %.2f\n",divide);

return 0;

}

首頁

2015年7月5日 星期日

判斷偶數和奇數

使用if...else來判斷偶數(Even)和奇數(Odd)

#include <stdio.h>

int main()

{

int n;

printf("Enter an integer\n");

scanf("%d", &n);

if (n%2 == 0)

printf("Even\n");

else printf("Odd\n");

return 0;

}

首頁