# C語言 程式設計 作品
## [變數](https://onlinegdb.com/sBiW8zgan)
:::info
```
#include <stdio.h>
int main(){
//建立變數
int myNum = 5; //整數
float myFloatNum = 5.99; //浮點數
char myLetter = 'D'; //字元
//輸出變數
printf("%d\n", myNum);
printf("%f\n", myFloatNum);
printf("%c\n", myLetter);
return 0;
}
//輸出 int 變數的值
//int a = 30;
// printf(" %d",a);
```
:::
## [如何判斷一個給定的數字是偶數還是奇數?](https://onlinegdb.com/wcF2YMiea)
:::success
```
#include <stdio.h>
int main()
{
int x =4 ;
if(x % 2 == 0){
printf("偶");}
else{
printf("奇");}
}
```
:::
## [輸入一個整數後即輸出該數的絶對值](https://onlinegdb.com/sWVgr0UAO)
:::warning
```
#include <stdio.h>
int main()
{
int x =-5 ;
if(x>0 )
{printf("%d",x );
}
if(x<0 )
{printf("%d",-x );
}
}
```
:::
## [正三角形、等腰三角形、直角三角形、普通三角形判斷](https://onlinegdb.com/4WWSgDKVxO)
:::danger
```
#include <stdio.h>
int main() {
int x=3; //線段 1
int y=3; //線段 2
int z=6; //線段 3
int xyz=0; //借用
if(x>y){
xyz = x;
x = y;
y = xyz;
}
if(y>z){
xyz = y;
y = z;
z = xyz;
}
int mm=x*x;
printf("%d\n",mm);
int hh=y*y;
printf("%d\n",hh);
int bb=z*z;
printf("%d\n",bb);
if(x+y>z){ //是三角形
if(x==y||y==z){
if(x==y&&y==z)
printf("正三角形");
else
printf("等腰三角形");
}
if(mm+hh==bb)
printf("直角三角形");
else if((x!=y||y!=z)||(x!=y&&y!=z))
printf("普通三角形");
}
else{
printf("不可");
}
}
```
:::
## [判斷三條線段是否可圍成一個三角形](https://onlinegdb.com/OIV2zwjjF)
:::info
```
#include <stdio.h>
int main() {
int x=555; //線段 1
int y=6; //線段 2
int z=12; //線段 3
if(x+y>z && x+z>y && y+z>x){
//是三角形
printf("可");
}
if(x+y<z || x+z<y || y+z<x){
//不是三角形
printf("不可");
}
}
```
:::
## [if、else練習](https://onlinegdb.com/EGZZvR3C5)
:::success
```
#include <stdio.h>
int main(){
int time = 24;
if (time < 12){
printf("早安");
}
else {
printf("午安");
}
}
```
:::
## [switch、case練習](https://onlinegdb.com/4uHoej1-s)
:::warning
```
#include <stdio.h>
int main(){
int day = 3;
switch (day) {
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
}
}
```
:::
## [if else if練習](https://onlinegdb.com/4Z0F-pxcq8)
:::danger
```
#include <stdio.h>
int main()
{
int time = 22;
if (time < 12) {
printf("Good morning.");
}
else if (time < 20) {
printf("Good day.");
}
else {
printf("Good evening.");
}
}
```
:::
## [1加到10](https://onlinegdb.com/BsCpcj_6z)
:::info
```
#include <stdio.h>
int main()
{
int i = 0;
int o = 1;
while (o < 11) {
i += o;
o += 1;
}
printf("%d\n", i);
}
```
:::
## [while練習](https://onlinegdb.com/4cJMi5wkY)
:::success
```
#include <stdio.h>
int main()
{
int i = 0;
while (i < 5) {
printf("%d\n", i);
i++;
}
}
```
:::
## [判斷一個整數,是質數還是合數,並找出所有的因數](https://onlinegdb.com/9jB09WlY8)
:::warning
```
#include <stdio.h>
int main()
{
int m, j = 7 , is_prime = 1
for (m = 2; m < j; m++){
if ( j % m == 0){
printf("%d\n", m);
is_prime = 0;
}
}
if (is_prime == 1)
printf("是質數");
else
printf("是合數");
}
```
:::
## [找零機器](https://onlinegdb.com/7kRywWwCM)
:::danger
```
#include <stdio.h>
int main()
{
int myNum;
scanf("%d", &myNum);
int m = myNum/100;//
int p = myNum%100;
int i = p/50;//
int o = p%50;
int l = o/10;//
int k = o%10;
int j = k/5;//
int y = k%5;
int h = y/1;//
printf("有%d個100元\n", m);
printf("有%d個50元\n", i);
printf("有%d個10元\n", l);
printf("有%d個5元\n", j);
printf("有%d個1元\n", h);
}
```
:::
## [身份證字號真偽判斷](https://onlinegdb.com/CEhGqhaSN)
:::info
```
#include <stdio.h>
int main()
{
char my;
char ij[9];
printf("請輸入身分證字號(請打大寫)\n");
scanf("%c", &my);
scanf("%s", ij);
printf("%c\n", my);
printf("%d\n", my);
for(int lsl = 0;lsl<9;lsl++)
ij[lsl] = ij[lsl]-48;
int m;
if(my== 'A')
m = 10;
if(my== 'B')
m = 11;
if(my== 'C')
m = 12;
if(my== 'D')
m = 13;
if(my=='E')
m = 14;
if(my=='F')
m = 15;
if(my=='G')
m = 16;
if(my=='H')
m = 17;
if(my=='I')
m = 34;
if(my=='J')
m = 18;
if(my=='K')
m = 19;
if(my=='L')
m = 20;
if(my=='M')
m = 21;
if(my=='N')
m = 22;
if(my=='O')
m = 35;
if(my=='P')
m = 23;
if(my=='Q')
m = 24;
if(my=='R')
m = 25;
if(my=='S')
m = 26;
if(my=='T')
m = 27;
if(my=='U')
m = 28;
if(my=='V')
m = 29;
if(my=='W')
m = 32;
if(my=='X')
m = 30;
if(my=='Y')
m = 31;
if(my=='Z')
m = 33;
printf("%d\n", m);
int f = m/10;
printf("%d\n", f);
int u = m%10;
printf("%d\n", u);
int x = u*9;
int y = ij[0]*8,h = ij[1]*7,jjj = ij[2]*6,kkk = ij[3]*5,lll = ij[4]*4,rrr = ij[5]*3,mmm = ij[6]*2;
int tttt = f+x+y+h+jjj+kkk+lll+rrr+mmm+ij[7]+ij[8];
printf("%d\n", tttt);
if (tttt%10==0)
printf("是身分證字號");
else
printf("不是身分證字號");
}
```
:::
## [冒牌費氏數列](https://onlinegdb.com/OUMX00BzTv)
:::success
```
#include <stdio.h>
int f(int n);
int main()
{
int n;
scanf("%d", &n);
printf("%d", f(n));
return 0;
}
int f(int n)
{
if (n == 1)
return 10;
if (n == 2)
return 15;
if (n == 3)
return 16;
return f(n - 2) + f(n - 3);
}
```
:::
## [終極密碼](https://onlinegdb.com/gJctBeRCOg)
:::warning
```
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
int y;
srand( time(NULL) );
int min;
int max;
scanf("%d", &min);
scanf("%d", &max);
int x = rand() % (max - min + 1) + min;
int z=0;
do
{
scanf("%d", &y);
if(x > y){
printf("%d~%d\n",y ,max);
}
if(x < y){
printf("%d~%d\n",y ,min);
}
z++;
}
while (x != y);
printf("Ya%d" ,z);
return 0;
}
```
:::
## [哈囉](https://zerojudge.tw/ShowProblem?problemid=a001)
:::danger
```
#include<stdio.h>
int main()
{
char string[100];
while(scanf("%s",string)!=EOF)
{
printf("hello, ");
printf("%s\n",string);
}
return 0;
}
```
:::
## [簡易加法](https://zerojudge.tw/ShowProblem?problemid=a002)
:::success
```
#include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d", a+b);
return 0;
}
```
:::
## [兩光法師占卜術](https://zerojudge.tw/ShowProblem?problemid=a003)
:::info
```
#include<stdio.h>
int main()
{
int M,D;
int sum;
while(scanf("%d%d",&M,&D)!=EOF)
{
sum=0;
sum=(M*2+D)%3;
if(sum==0)
printf("普通\n");
else if(sum==1)
printf("吉\n");
else if(sum==2)
printf("大吉\n");
}
return 0;
}
```
:::
## [文文的求婚](https://zerojudge.tw/ShowProblem?problemid=a004)
:::warning
```
#include <stdio.h>
int main() {
//宣告變數year,代表西元年
int year;
//使用EOF寫法判斷程式執行的條件
while(scanf("%d", &year) != EOF) {
//根據題意,西元年被4整除且不被100整除,或被400整除者即為閏年
if(year%4 == 0 && year%100 != 0 || year%400 == 0)
printf("閏年\n");
else
printf("平年\n");
}
return 0;
}
```
:::
## [Eva 的回家作業](https://zerojudge.tw/ShowProblem?problemid=a005)
:::danger
```
#include <stdio.h>
int main() {
// 宣告並讀取變數t,代表數列的數目
int t;
scanf("%d", &t);
// 使用for迴圈分別討論每一個數列的情況
for(int i = 0 ; i < t ; i++) {
// 宣告並讀取陣列a[4],代表輸入數列的前四項
int a[4];
scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]);
// 若數列任兩項間的差相同,即為等差數列
if(a[1]-a[0] == a[2]-a[1])
printf("%d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[3]+(a[1]-a[0]));
// 若否,即為等比數列
else
printf("%d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[3]*(a[1]/a[0]));
}
return 0;
}
```
:::
## [一元二次方程式](https://zerojudge.tw/ShowProblem?problemid=a006)
:::success
```
#include <stdio.h>
#include <math.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
int D = b*b-4*a*c;
if(D < 0)
printf("No real root\n");
else {
int x1 = (-b+sqrt(D))/(2*a);
int x2 = (-b-sqrt(D))/(2*a);
if(D > 0)
printf("Two different roots x1=%d , x2=%d", x1, x2);
else if(D == 0)
printf("Two same roots x=%d", x1);
}
return 0;
}
```
:::
## 下一次我想要
:::spoiler

## 在這個社團中,你們一起探索程式語言的奧秘,這個過程不僅提升了你的程式設計技能,更讓你學會了如何與他人合作,如何共同解決問題。當你們一起解決難題時,你們彼此之間的信賴和合作無疑會得到加強。而當你們分享成功的喜悅時,這種成就感會讓你們更加堅定地走下去。
## 這樣的經驗,不僅讓你在技術上有所成長,更在人際關係和團隊合作方面有所提升。這是一個非常寶貴的經驗,希望你能繼續保持這樣的熱情和投入,相信你在未來一定能有更大的成就。

:::info
## 從我第一次聽說"C語言社團"的那一刻起,我就對它充滿了興趣和期待。我期待能透過這個社團,學習到C語言的知識,並在實踐中提升自己的程式設計技能。
## C語言是一種強大而靈活的程式語言,它的應用範疇廣泛,從操作系統到嵌入式系統都有其身影。我期待能掌握這門語言,並將其應用在解決實際問題上。
## 除此之外,我也期待在"C語言社團"裡,能遇到一群和我一樣對C語言充滿熱情的朋友。我們可以一起學習,一起進步,一起分享我們的成功和挫折。我相信,這樣的經驗將對我們的學習和成長都有莫大的幫助。
## 我對"C語言社團"充滿了期待,我相信在這裡,我將獲得豐富的知識,寶貴的經驗,以及一生的朋友。我期待在未來的日子裡,我能在這個社團裡學到更多,也能與這群朋友一起創造更多美好的回憶。
:::success
:::
# 我八年級了
## 程式:
### [哈囉](https://zerojudge.tw/ShowProblem?problemid=a001)
```
#include<stdio.h>
int main()
{
char string[100];
while(scanf("%s",string)!=EOF)
{
printf("hello, ");
printf("%s\n",string);
}
return 0;
}
```
### [簡易加法](https://zerojudge.tw/ShowProblem?problemid=a002)
```
#include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d", a+b);
return 0;
}
```
### [兩光法師占卜術](https://zerojudge.tw/ShowProblem?problemid=a003)
```
#include<stdio.h>
int main()
{
int M,D;
int sum;
while(scanf("%d%d",&M,&D)!=EOF)
{
sum=0;
sum=(M*2+D)%3;
if(sum==0)
printf("普通\n");
else if(sum==1)
printf("吉\n");
else if(sum==2)
printf("大吉\n");
}
return 0;
}
```
### [文文的求婚](https://zerojudge.tw/ShowProblem?problemid=a004)
```
#include <stdio.h>
int main() {
//宣告變數year,代表西元年
int year;
//使用EOF寫法判斷程式執行的條件
while(scanf("%d", &year) != EOF) {
//根據題意,西元年被4整除且不被100整除,或被400整除者即為閏年
if(year%4 == 0 && year%100 != 0 || year%400 == 0)
printf("閏年\n");
else
printf("平年\n");
}
return 0;
}
```
### [Eva 的回家作業 ](https://zerojudge.tw/ShowProblem?problemid=a005)
```
#include <stdio.h>
int main() {
// 宣告並讀取變數t,代表數列的數目
int t;
scanf("%d", &t);
// 使用for迴圈分別討論每一個數列的情況
for(int i = 0 ; i < t ; i++) {
// 宣告並讀取陣列a[4],代表輸入數列的前四項
int a[4];
scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]);
// 若數列任兩項間的差相同,即為等差數列
if(a[1]-a[0] == a[2]-a[1])
printf("%d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[3]+(a[1]-a[0]));
// 若否,即為等比數列
else
printf("%d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[3]*(a[1]/a[0]));
}
return 0;
}
```
### [一元二次方程式 ](https://zerojudge.tw/ShowProblem?problemid=a006)
```
#include <stdio.h>
#include <math.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
int D = b*b-4*a*c;
if(D < 0)
printf("No real root\n");
else {
int x1 = (-b+sqrt(D))/(2*a);
int x2 = (-b-sqrt(D))/(2*a);
if(D > 0)
printf("Two different roots x1=%d , x2=%d", x1, x2);
else if(D == 0)
printf("Two same roots x=%d", x1);
}
return 0;
}
```
### [解碼器](https://zerojudge.tw/ShowProblem?problemid=a009)
```
#include <stdio.h>
#include <string.h>
int main() {
//以字元陣列的形式宣告,並以字串的形式讀取輸入的明碼
char arr[1000];
scanf("%s", arr);
//利用for迴圈,逐項將明碼轉為密碼
for(int i = 0 ; i < strlen(arr) ; i++)
arr[i] = arr[i]-7;
printf("%s", arr);
return 0;
}
```
### [因數分解](https://zerojudge.tw/ShowProblem?problemid=a010)
```
#include <stdio.h>
int main() {
int num;
scanf("%d", &num);
for(int factor = 2 ; factor <= num ; factor++) {
if(num%factor == 0) {
int power = 0;
while(num%factor == 0) {
num /= factor;
power++;
}
if(power == 1)
printf("%d", factor);
else
printf("%d^%d", factor, power);
if(num != 1)
printf(" * ");
}
}
return 0;
}
```
### [羅馬數字](https://zerojudge.tw/ShowProblem?problemid=a013)
```
#include<stdio.h>
#include<math.h>
#include<string.h>
int char_to_number(char []);
int main(){
int dif;
char array1 [30]={'\0'};
char array2 [30]={'\0'};
while(scanf("%s",array1)!=EOF)
{
char s[30]={0};
if(array1[0]=='#')
break;
scanf("%s",array2);
dif=abs(char_to_number(array1)-char_to_number(array2));
if(dif==0)
printf("ZERO\n");
else
{
int i=0;
while(dif>=1000)
{
dif-=1000;
s[i]='M';
i++;
}
if(dif>=900)
{
dif-=900;
s[i]='C';
s[i+1]='M';
i+=2;
}
if(dif>=500)
{
dif-=500;
s[i]='D';
i++;
}
if(dif>=400)
{
dif-=400;
s[i]='C';
s[i+1]='D';
i+=2;
}
while(dif>=100)
{
dif-=100;
s[i]='C';
i++;
}
if(dif>=90)
{
dif-=90;
s[i]='X';
s[i+1]='C';
i+=2;
}
if(dif>=50)
{
dif-=50;
s[i]='L';
i++;
}
if(dif>=40)
{
dif-=40;
s[i]='X';
s[i+1]='L';
i+=2;
}
while(dif>=10)
{
dif-=10;
s[i]='X';
i++;
}
if(dif>=9)
{
dif-=9;
s[i]='I';
s[i+1]='X';
i+=2;
}
if(dif>=5)
{
dif-=5;
s[i]='V';
i++;
}
if(dif>=4)
{
dif-=4;
s[i]='I';
s[i+1]='V';
i+=2;
}
while(dif>=1)
{
dif-=1;
s[i]='I';
i++;
}
}
printf("%s\n",s);
}
return 0;
}
int char_to_number(char s[])
{
int sum=0;
int i;
for(i=0;i<strlen(s);i++){
if(s[i]=='C'&&s[i+1]=='M')
{ sum-=100; }
else if(s[i]=='C'&&s[i+1]=='D')
{ sum-=100; }
else if(s[i]=='X'&&s[i+1]=='C')
{ sum-=10; }
else if(s[i]=='X'&&s[i+1]=='L')
{ sum-=10; }
else if(s[i]=='I'&&s[i+1]=='X')
{ sum-=1; }
else if(s[i]=='I'&&s[i+1]=='V')
{ sum-=1; }
else if(s[i]=='I')
{ sum+=1; }
else if(s[i]=='V')
{ sum+=5; }
else if(s[i]=='X')
{ sum+=10; }
else if(s[i]=='L')
{ sum+=50; }
else if(s[i]=='C')
{ sum+=100; }
else if(s[i]=='D')
{ sum+=500; }
else if(s[i]=='M')
{ sum+=1000; }
}
return sum;
}
```
### [矩陣的翻轉](https://zerojudge.tw/ShowProblem?problemid=a015)
```
#include<stdio.h>
void ReadArray(int,int,int [100][100]);
void PrintArray(int ,int,int [100][100]);
int main(){
int i,j;
int m,n;
int array1[100][100];
while(scanf("%d %d",&m,&n)!=EOF)
{
ReadArray(m,n,array1);
PrintArray(m,n,array1);
}
return 0;
}
void ReadArray(int m,int n,int array[100][100]){
int i,j;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&array[i][j]);
}
}
}
void PrintArray(int m,int n,int array[100][100])
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%d ",array[j][i]);
}
printf("\n");
} printf("\n");
}
```
### [身分證檢驗](https://zerojudge.tw/ShowProblem?problemid=a020)
```
#include<stdio.h>
#include<string.h>
int main(){
char identity[11];
int check[11];
int i;
int sum,temp;
while(scanf("%s",&identity)!=EOF)
{
if(identity[0]=='A')
{
check[0]=1;
check[1]=0;
}
if(identity[0]=='B')
{
check[0]=1;
check[1]=1;
}
if(identity[0]=='C')
{
check[0]=1;
check[1]=2;
}
if(identity[0]=='D')
{
check[0]=1;
check[1]=3;
}
if(identity[0]=='E')
{
check[0]=1;
check[1]=4;
}
if(identity[0]=='F')
{
check[0]=1;
check[1]=5;
}
if(identity[0]=='G')
{
check[0]=1;
check[1]=6;
}
if(identity[0]=='H')
{
check[0]=1;
check[1]=7;
}
if(identity[0]=='I')
{
check[0]=3;
check[1]=4;
}
if(identity[0]=='J')
{
check[0]=1;
check[1]=8;
}
if(identity[0]=='K')
{
check[0]=1;
check[1]=9;
}
if(identity[0]=='L')
{
check[0]=2;
check[1]=0;
}
if(identity[0]=='M')
{
check[0]=2;
check[1]=1;
}
if(identity[0]=='N')
{
check[0]=2;
check[1]=2;
}
if(identity[0]=='O')
{
check[0]=3;
check[1]=5;
}
if(identity[0]=='P')
{
check[0]=2;
check[1]=3;
}
if(identity[0]=='Q')
{
check[0]=2;
check[1]=4;
}
if(identity[0]=='R')
{
check[0]=2;
check[1]=5;
}
if(identity[0]=='S')
{
check[0]=2;
check[1]=6;
}
if(identity[0]=='T')
{
check[0]=2;
check[1]=7;
}
if(identity[0]=='U')
{
check[0]=2;
check[1]=8;
}
if(identity[0]=='V')
{
check[0]=2;
check[1]=9;
}
if(identity[0]=='W')
{
check[0]=3;
check[1]=2;
}
if(identity[0]=='X')
{
check[0]=3;
check[1]=0;
}
if(identity[0]=='Y')
{
check[0]=3;
check[1]=1;
}
if(identity[0]=='Z')
{
check[0]=3;
check[1]=3;
}
for(i=1;i<10;i++)
{
if(identity[i]=='0')
check[i+1]=0;
if(identity[i]=='1')
check[i+1]=1;
if(identity[i]=='2')
check[i+1]=2;
if(identity[i]=='3')
check[i+1]=3;
if(identity[i]=='4')
check[i+1]=4;
if(identity[i]=='5')
check[i+1]=5;
if(identity[i]=='6')
check[i+1]=6;
if(identity[i]=='7')
check[i+1]=7;
if(identity[i]=='8')
check[i+1]=8;
if(identity[i]=='9')
check[i+1]=9;
}
sum=0;
sum=check[0]+check[10];
for(i=1;i<10;i++)
{
temp=check[i]*(10-i);
sum+=temp;
}
if(sum%10==0)
printf("real\n");
else
printf("fake\n");
}
return 0;
}
```
### [迴文](https://zerojudge.tw/ShowProblem?problemid=a022)
```
#include <stdio.h>
#include <string.h>
int main() {
//宣告並讀取陣列arr,代表輸入的字串
char arr[1000];
scanf("%s", arr);
//宣告變數count,代表前後對稱的組數
int count = 0;
//迴文字串必然對稱,因此我們可以檢查該字串前後對應到的項是否相同
//若發現字串的任一組頭尾不同,即非迴文,輸出no後跳出迴圈
for(count = 0 ; count < strlen(arr)/2 ; count++) {
if(arr[count] != arr[(strlen(arr)-1)-count]) {
printf("no");
break;
}
}
//即非迴文到字串的一半都未發現不同的組,則為迴文,輸出yes
if(count == strlen(arr)/2)
printf("yes");
return 0;
}
```
### [最大公因數(GCD)](https://zerojudge.tw/ShowProblem?problemid=a024)
```
#include <stdio.h>
int main() {
//宣告變數a、b,代表輸入的兩個整數
int a, b;
scanf("%d%d", &a, &b);
//宣告變數big、small,分別代表兩數中較大和較小的數字
int big = (a > b) ? a : b;
int small = (a > b) ? b : a;
//輾轉相除法:將兩數中較大的數字除以較小的數字,
//原來較小的數字作為新的運算中教大的數字,餘作為新的運算中較小的數字
//直到其一為0時運算結束,剩下的數字就是兩數的最大公因數
while(small != 0) {
int temp = big;
big = small;
small = temp%small;
}
printf("%d", big);
return 0;
}
```
### [二進位制轉換](https://zerojudge.tw/ShowProblem?problemid=a034)
```
#include <stdio.h>
#include <math.h>
int main() {
int dec;
while(scanf("%d", &dec) != EOF) {
int bin[32] = {}, non_zero_digit = 0;
for(int n = 31, i = 0 ; n >= 0 ; n--, i++) {
if(dec >= pow(2, n)) {
bin[i] = 1;
dec -=pow(2, n);
non_zero_digit++;
}
else
bin[i] = 0;
if(bin[i] != 0 || non_zero_digit != 0)
printf("%d", bin[i]);
}
printf("\n");
}
return 0;
}
```
### [數字翻轉](https://zerojudge.tw/ShowProblem?problemid=a038)
```
#include <stdio.h>
#include <string.h>
int main() {
//宣告並讀取字元陣列num,代表輸入的數字
char num[10];
scanf("%s", num);
//宣告變數test,並設初始值為0,記錄前面是否有輸出過非零數字
//若test為0,代表之前尚未輸出過非零數字,這一位數若是0即為前綴0,不需輸出
//若test為1,代表之前已經輸出過非零數字,這一位數就算是0也不是前綴0,需輸出
int test = 0;
for(int i = 0 ; i < strlen(num) ; i++)
if(num[(strlen(num)-1)-i] != '0' || test != 0) {
printf("%c", num[(strlen(num)-1)-i]);
//輸出後將test設為1,代表已經輸出過非零數字
test=1;
}
//若test仍為0,說明直到跑完指個陣列都未曾輸出過非零數字,也就是說這個數字就是0
if(test == 0)
printf("0");
return 0;
}
```
### [阿姆斯壯數](https://zerojudge.tw/ShowProblem?problemid=a040)
```
#include <stdio.h>
#include <math.h>
int main() {
//宣告並讀取變數n、m,代表判斷範圍的上下限
int n, m, test = 0;
scanf("%d %d", &n, &m);
//利用for迴圈跑從n到m的所有數字
for(int num = n ; num <= m ; num++) {
//宣告變數num,代表檢查到的數;宣告變數len,代表此數的位數
int i = num, len = 1;
//若此數大於等於10,就將其除以10,並將len加一
while(i >= 10) {
i /= 10;
len++;
}
//宣告變數sum,代表各個位數的總和
int sum = 0;
//從最高位開始,將此數的各個位數len次方後相加
for(int i = len ; i > 0 ; i--)
//num為目前判斷的數字,共len位數,i代表目前檢查到的位數
//將num%pow(10, i)即可得num在i位以後(含)的數字,/pow(10, i-1)可得num在i-1位以前的數字,即為第i位數字
sum += pow((num%(int)pow(10, i)/(int)pow(10, i-1)), len);
//若此len位數的數字,各個位數的len次方和等於自己,即為阿姆斯壯數,需輸出
if(sum == num) {
printf("%d ", num);
test++;
}
}
//若範圍內的數字皆無阿姆斯壯數,輸出None
if(test == 0)
printf("none");
return 0;
}
```
### [費波那契數列](https://onlinegdb.com/Pzc6Hm1-dm)
```
#include <stdio.h>
int f(int m);
int main(){
int l;
scanf("%d", &l);
int t[] = {1,1};
printf("%d",f(l));
return 0;
}
int f(int n){
if(n == 0) { // 如果n等於0
return 0;
}
if(n == 1) { // 如果n等於1
return 1;
}
return f(n - 1) + f(n - 2); // 其他情形
}
```
### [桃園市公立高中職落點評估](https://onlinegdb.com/Pzc6Hm1-dm)
```
#include <stdio.h>
#include <string.h>
// 字串比對並回傳對應點數
int gradeToPoints(const char* grade) {
if (strcmp(grade, "A++") == 0) return 7;
else if (strcmp(grade, "A+") == 0) return 6;
else if (strcmp(grade, "A") == 0) return 5;
else if (strcmp(grade, "B++") == 0) return 4;
else if (strcmp(grade, "B+") == 0) return 3;
else if (strcmp(grade, "B") == 0) return 2;
else if (strcmp(grade, "C") == 0) return 1;
else return 0;
}
// 作文級分轉換
int essayScore(int level) {
if (level <= 1) return level;
if (level <= 3) return 2;
return 3;
}
int main() {
char chineseGrade[4], mathGrade[4], scienceGrade[4], socialGrade[4], englishGrade[4];
int essayLevel;
int totalPoints = 0, totalScore = 0;
// 輸入
printf("請輸入國文成績(A++、A+、A、B++、B+、B、C):");
scanf("%s", chineseGrade);
printf("請輸入數學成績:");
scanf("%s", mathGrade);
printf("請輸入自然成績:");
scanf("%s", scienceGrade);
printf("請輸入社會成績:");
scanf("%s", socialGrade);
printf("請輸入英文成績:");
scanf("%s", englishGrade);
printf("請輸入作文級分(0到6):");
scanf("%d", &essayLevel);
// 加總點數
totalPoints += gradeToPoints(chineseGrade);
totalPoints += gradeToPoints(mathGrade);
totalPoints += gradeToPoints(scienceGrade);
totalPoints += gradeToPoints(socialGrade);
totalPoints += gradeToPoints(englishGrade);
// 加作文分數
totalScore = totalPoints + essayScore(essayLevel);
// 輸出結果
printf("總點數是:%d\n", totalPoints);
printf("總分(包含作文分數)是:%d\n", totalScore);
// 落點判斷
if (totalScore >= 33) {
printf("🎓 您符合武陵高中的錄取標準!\n");
} else if (totalScore >= 31) {
printf("🎓 您符合中壢高中或桃園高中的錄取標準!\n");
} else if (totalScore >= 29) {
printf("🎓 您符合平鎮高中的錄取標準!\n");
} else if (totalScore >= 27) {
printf("🎓 您符合陽明、永豐、大園等高中的錄取標準!\n");
} else {
printf("⚠️ 目前未達錄取標準,請參考備取學校或技職方向。\n");
}
return 0;
}
```
### HTML + JavaScript 程式(網頁互動版)桃園市公立高中職落點評估
```
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
<meta charset="UTF-8">
<title>桃園市 高中職落點評估系統</title>
<style>
body {
font-family: '微軟正黑體', sans-serif;
padding: 20px;
background-color: #f9f9f9;
}
h1 {
color: #2c3e50;
}
label {
display: block;
margin-top: 10px;
}
input, select {
padding: 5px;
margin-top: 5px;
width: 150px;
}
button {
margin-top: 20px;
padding: 10px 20px;
font-size: 16px;
}
#result {
margin-top: 30px;
padding: 15px;
background-color: #eef;
border-radius: 8px;
}
</style>
</head>
<body>
<h1>🎓 桃園市高中職落點評估系統</h1>
<form id="scoreForm">
<label>國文成績:
<select id="chinese">
<option>A++</option><option>A+</option><option>A</option>
<option>B++</option><option>B+</option><option>B</option><option>C</option>
</select>
</label>
<label>數學成績:
<select id="math">
<option>A++</option><option>A+</option><option>A</option>
<option>B++</option><option>B+</option><option>B</option><option>C</option>
</select>
</label>
<label>自然成績:
<select id="science">
<option>A++</option><option>A+</option><option>A</option>
<option>B++</option><option>B+</option><option>B</option><option>C</option>
</select>
</label>
<label>社會成績:
<select id="social">
<option>A++</option><option>A+</option><option>A</option>
<option>B++</option><option>B+</option><option>B</option><option>C</option>
</select>
</label>
<label>英文成績:
<select id="english">
<option>A++</option><option>A+</option><option>A</option>
<option>B++</option><option>B+</option><option>B</option><option>C</option>
</select>
</label>
<label>作文級分(0~6):
<input type="number" id="essay" min="0" max="6" required>
</label>
<button type="button" onclick="evaluate()">進行評估</button>
</form>
<div id="result"></div>
<script>
function gradeToPoints(grade) {
switch (grade) {
case "A++": return 7;
case "A+": return 6;
case "A": return 5;
case "B++": return 4;
case "B+": return 3;
case "B": return 2;
case "C": return 1;
default: return 0;
}
}
function essayScore(level) {
level = parseInt(level);
if (level <= 1) return level;
if (level <= 3) return 2;
return 3;
}
function evaluate() {
const chinese = document.getElementById("chinese").value;
const math = document.getElementById("math").value;
const science = document.getElementById("science").value;
const social = document.getElementById("social").value;
const english = document.getElementById("english").value;
const essay = document.getElementById("essay").value;
let totalPoints = 0;
totalPoints += gradeToPoints(chinese);
totalPoints += gradeToPoints(math);
totalPoints += gradeToPoints(science);
totalPoints += gradeToPoints(social);
totalPoints += gradeToPoints(english);
const totalScore = totalPoints + essayScore(essay);
let resultText = `🧮 總點數:${totalPoints}<br>`;
resultText += `📝 總分(含作文):${totalScore}<br><br>`;
if (totalScore >= 33) {
resultText += "🎓 您符合 <b>武陵高中</b> 的錄取標準!";
} else if (totalScore >= 31) {
resultText += "🎓 您符合 <b>中壢高中</b> 或 <b>桃園高中</b> 的錄取標準!";
} else if (totalScore >= 29) {
resultText += "🎓 您符合 <b>平鎮高中</b> 的錄取標準!";
} else if (totalScore >= 27) {
resultText += "🎓 您符合 <b>陽明、永豐、大園高中</b> 的錄取標準!";
} else {
resultText += "⚠️ 尚未達錄取分數,請考慮其他學校或技職選項。";
}
document.getElementById("result").innerHTML = resultText;
}
</script>
</body>
</html>
```