---
# System prepended metadata

title: OOP SYSTEM 解題解答

---

OOP SYSTEM 解題解答
===
:::info
歡迎大家一起來編輯，這是專為(https://oop.seilab.uk/) 所撰寫的解答，只要答案能過，不限方法，都可以放上來。感謝所有參與編輯的人！
:::
:::warning

抱歉占用各位的版面，我是你們的某一位學長

我覺得開共筆一起分享程式碼的這個想法很棒，可以互相交流彼此的思路，但是要稍微注意一下老師們的看法喔

有些老師會介意這種code level的交流，嚴重點來說其實你們現在的行為老師有可能會認為你們在給其他人抄作業

所以這種情況我會比較建議私下進行啦，畢竟班群有老師在，就怕老師誤會

除此之外，我也建議各位可以將程式碼整理成一份github專案，這樣管理起來也會比較方便，而且也可以隨時存取

將專案設成公開的話其他人也都看得到了喔(我也是這麼做的
:::
ch01_
---
ch02_Fundamentals
---
### 1. cp02-01_Hello World!!
```c=
#include<stdio.h>
int main (void){
    printf("Hello World!");
    return 0;
}
```
### 2. cp02-02_print
```c=
#include<stdio.h>
int main (void){
    printf("    *\n");
    printf("   ***\n");
    printf("  *****\n");
    printf(" *******\n");
    printf("  *****\n");
    printf(" *******\n");
    printf("*********\n");
    printf("    *\n");
    printf("    *\n");
    return 0;
}
```
### 3. cp02-02.1_printf
```c=
```
### 4. cp02ex_03_依範例撰寫程式
```c=
```
### 5. cp02-03_Dimensional Weight of a Box
```c=
```
### 6. cp02-04_Dimensional Weight of a Box 2(input)
```c=
```
### 7. cp02-05_攝氏轉華氏
```c=
```
### 8. cp02h-01
```c=
#include <stdio.h>

int main() {
    const float pi = 3.14159f;
    float radius;
    float volume;

    scanf("%f", &radius);

    volume = (4.0f / 3.0f) * pi * radius * radius * radius;

    printf("%.2f", volume);

    return 0;
}
```
### 9. cp02h-02
```c=
#include <stdio.h>

int main() {
    int amount;
    float totalAmount;

    scanf("%d", &amount);

    totalAmount = amount * 1.05f;  

    printf("%.2f", totalAmount);  

    return 0;
}
```
### 10. cp02h-03
```c=
#include <stdio.h>

int main() {
    int x;
    int result;

    scanf("%d", &x);

    result = 3 * x * x * x * x * x + 2 * x * x * x * x - 5 * x * x * x - x * x + 7 * x - 6;

    printf("%d", result);

    return 0;
}
```
### 11. cp02h-04
```c=
#include <stdio.h>

int main() {
    int amount, twenties, tens, fives, ones;

    scanf("%d", &amount);

    twenties = amount / 20;
    amount -= twenties * 20;

    tens = amount / 10;
    amount -= tens * 10;

    fives = amount / 5;
    amount -= fives * 5;

    ones = amount;

    printf("%d %d %d %d", twenties, tens, fives, ones);

    return 0;
}
```
### 12. cp02h-05
```c=
#include <stdio.h>

int main() {
    float loan_amount, interest_rate, monthly_payment;
    
    scanf("%f", &loan_amount);

    scanf("%f", &interest_rate);
 
    scanf("%f", &monthly_payment);

    float monthly_interest_rate = (interest_rate / 100.0) / 12.0;

    loan_amount = loan_amount - monthly_payment + (loan_amount * monthly_interest_rate);
    printf("$%.2f\n", loan_amount);
    
    loan_amount = loan_amount - monthly_payment + (loan_amount * monthly_interest_rate);
    printf("$%.2f\n", loan_amount);
    
    loan_amount = loan_amount - monthly_payment + (loan_amount * monthly_interest_rate);
    printf("$%.2f\n", loan_amount);
    
    return 0;
}
```
ch03_上課練習_Formatted_Input_Output
---
### 1. cp3_01_ex1
```c=

```
### 2. ch03_
```c=
#include <stdio.h>

int main(void) {
    int num1, den1, num2, den2;
    
    scanf("%d/%d", &num1, &den1);
    scanf("%d/%d", &num2, &den2);
    
    int result_num = num1 * num2;
    int result_den = den1 * den2;
    
    printf("%d/%d", result_num, result_den);
    
    return 0;
}
```
### 3. cp3_01_tprintf
```c=

```
### 4. cp3_02_addfrac
```c=
#include <stdio.h>
int main(void){
  int num1, denom1, num2, denom2, result_num, result_denom;
  printf("Enter first fraction:");
  scanf("%d/%d", &num1, &denom1);
  printf("Enter second fraction:");
  scanf("%d/%d", &num2, &denom2);
    
  result_num = num1 * denom2 + num2 * denom1;
  result_denom=denom1*denom2;
    
  printf("The sum is %d/%d", result_num, result_denom);
    
  return 0; 
}
```
### 5. cp3_03 
```c=
#include<stdio.h>
int main (void){
    int day,mon,year;
    
    printf("Enter a date (mm/dd/yyyy):");
    scanf("%d/%d/%d",&mon,&day,&year);
    
    printf("You entered the date %d%02d%02d",year,mon,day);
    
    return 0;
}
```
### 6. cp3_04
```c=
#include <stdio.h>

int main(void) {
    int num1, denom1, num2, denom2, result_num, result_denom;

    printf("Enter two fractions separated by a plus sign:");
    scanf("%d/%d +%d/%d", &num1, &denom1, &num2, &denom2);

    result_num = num1 * denom2 + num2 * denom1;
    result_denom = denom1 * denom2;

    printf("The sum is %d/%d", result_num, result_denom);

    return 0;
}
```
### 7. cp3h_03
```c=
#include<stdio.h>
int main(void){
	int a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16;
    scanf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",&a1,&a2,&a3,&a4,&a5,&a6,&a7,&a8,&a9,&a10,&a11,&a12,&a13,&a14,&a15,&a16);
	printf("%2d %2d %2d %2d\n",a1,a2,a3,a4);
    printf("%2d %2d %2d %2d\n",a5,a6,a7,a8);
    printf("%2d %2d %2d %2d\n",a9,a10,a11,a12);
    printf("%2d %2d %2d %2d\n",a13,a14,a15,a16);
    printf("\nRow sums: %d %d %d %d\n",a1+a2+a3+a4,a5+a6+a7+a8,a9+a10+a11+a12,a13+a14+a15+a16);
	printf("Column sums: %d %d %d %d\n",a1+a5+a9+a13,a2+a6+a10+a14,a3+a7+a11+a15,a4+a8+a12+a16);
    printf("Diagonal sums: %d %d",a1+a6+a11+a16,a4+a7+a10+a13);
	return 0;
}
```
### 8. cp3h_01
```c=
#include <stdio.h>

int main(void) {
    int item_number, month, day, year;
    float unit_price;


    scanf("%d", &item_number);

   
    scanf("%f", &unit_price);

    scanf("%d/%d/%d", &month, &day, &year);


    printf("Item\t\tUnit\t\tPurchase\n");
    printf("\tPrice\t\tDate\n");
    printf("%d\t\t$%4.2f\t\t%02d/%02d/%d\n", item_number, unit_price, month, day, year);

    return 0;
}
```
### 9. cp3h_02
```c=
#include <stdio.h>

int main(void) {
    char phone[20];
    
    scanf("(%2s) %4s-%4s", phone, phone + 3, phone + 8);
    
    printf("You entered %s.%s.%s", phone, phone + 3, phone + 8);
    
    return 0;
}
```
### 10. ch03_Adding Fractions
```c=
#include <stdio.h>

int main(void) {
    int num1, denom1, num2, denom2;
    
    scanf("%d/%d", &num1, &denom1);
    scanf("%d/%d", &num2, &denom2);

    int sum_num = num1 * denom2 + num2 * denom1;
    int sum_denom = denom1 * denom2;

    printf("%d/%d", sum_num, sum_denom);

    return 0;
}
```
### 11. ch03_Subtracting Fractions
```c=
#include <stdio.h>

int main(void) {
    int num1, denom1, num2, denom2;

    scanf("%d/%d", &num1, &denom1);
    scanf("%d/%d", &num2, &denom2);
    
    int sub_num = num1 * denom2 - num2 * denom1;
    int sub_denom = denom1 * denom2;

    printf("%d/%d", sub_num, sub_denom);

    return 0;
}
```
### 12. ch03_Adding Fractions plus
```c=
#include <stdio.h>

int main(void) {
    int num1, denom1, num2, denom2, num3, denom3;

    scanf("%d/%d", &num1, &denom1);
    scanf("%d/%d", &num2, &denom2);
    scanf("%d/%d", &num3, &denom3);
    
    int sum_num = num1 * denom2 * denom3 + num2 * denom1 * denom3 + num3 * denom1 * denom2;
    int sum_denom = denom1 * denom2 * denom3;

    printf("%d/%d", sum_num, sum_denom);

    return 0;
}
```
ch04_上課練習
---
### 1. ch04_Computing a UPC Check Digit 1
```c=
#include <stdio.h>
int main(){

    int first;
    scanf("%1d",&first);
    int a,b,c,d,e;
    scanf("%1d%1d%1d%1d%1d",&a,&b,&c,&d,&e);
    int f,g,h,i,j;
    scanf("%1d%1d%1d%1d%1d",&f,&g,&h,&i,&j);
    
    int sum1,sum2,total;

    sum1 = first + b + d + f + h + j;
    sum2 = a + c + e + g + i;

    total =(3 * sum1) + sum2;

    int last;

    last = 9 - ((total-1) % 10);
    printf("%d",last);

    return 0;
}
```
### 2. ch04_Computing a UPC Check Digit 2
```c=
#include <stdio.h>
int main(){

    int first;
    scanf("%1d",&first);
    int a,b,c,d,e;
    scanf("%1d%1d%1d%1d%1d",&a,&b,&c,&d,&e);
    int f,g,h,i,j;
    scanf("%1d%1d%1d%1d%1d",&f,&g,&h,&i,&j);
    
    int sum1,sum2,sum3,total;

    sum1 = first + c + f + i;
    sum2 = a + d + g + j;
    sum3 = b + e + h;

    total =(3 * sum1) + sum2 + sum3;

    int last;

    last = 9 - ((total-1) % 10);
    printf("%d",last);

    return 0;
}
```
### 3. ch04_Computing a UPC Check Digit 3
```c=
#include <stdio.h>
int main(){

    int first;
    scanf("%1d",&first);
    int a,b,c,d;
    scanf("%1d%1d%1d%1d",&a,&b,&c,&d);
    int e,f,g,h;
    scanf("%1d%1d%1d%1d",&e,&f,&g,&h);
    int i,j,k,l;
    scanf("%1d%1d%1d%1d",&i,&j,&k,&l);
    
    int sum1,sum2,sum3,total;

    sum1 = first + b + d + f + h;
    sum2 = a + c + e + g;
    sum3 = i + j + k + l;

    total =((2 * sum1) + sum2 + sum3) + 5;

    int last;

    last = 9 - (total % 7);
    printf("%d",last);

    return 0;
}
```
### 4. ch04_3.1_Expression_Evaluation_01
```c=
#include<stdio.h>
int main(void){
    printf("(a = (b += (((c++) - d) + ((--e) / (-f)))))");
    
    return 0;
}
```
ch04_Homework
---
### 1. ch4_01_upc
```c=
#include <stdio.h>
int main(void){
    int d, i1, i2, i3, i4, i5, j1, j2, j3, j4, j5,first_sum, second_sum, total;
    
    printf("Enter the first (single) digit:");
    scanf("%1d", &d);
    
    printf("Enter first group of five digits:");
    scanf("%1d%1d%1d%1d%1d", &i1, &i2, &i3, &i4, &i5);
    
    printf("Enter second group of five digits:");
    scanf("%1d%1d%1d%1d%1d", &j1, &j2, &j3, &j4, &j5);
    
    first_sum = d + i2 + i4 + j1 + j3 + j5;
    second_sum = i1 + i3 + i5 + j2 + j4;
    total = 3 * first_sum + second_sum;
    
    printf("Check digit: %d", 9 - ((total - 1) % 10));
    
    return 0; 
}

```
### 2. cp4h_01
```c=
#include <stdio.h>

int main() {
    int number, reversed;

    printf("Enter a two-digit number:");
    scanf("%d", &number);

    reversed = (number % 10) * 10 + (number / 10);

    printf("The reversal is %02d", reversed);

    return 0;
}
```
### 3. cp4h_02
```c=
#include <stdio.h>

int main(){
    int number, reversed;

    printf("Enter a three-digit number:");
    scanf("%d", &number);

    reversed = (number % 10) * 100 + ((number / 10) % 10) * 10 + (number / 100);

    printf("The reversal is %03d", reversed);

    return 0;
}
```
### 4. cp4h_03
```c=
#include <stdio.h>

int main() {
    int number;

    printf("Enter a three-digit number:");
    scanf("%d", &number);

    int reversed[3];

    reversed[0] = (number % 100) % 10;
    reversed[1] = (number % 100) / 10;
    reversed[2] = number / 100;

    printf("The reversal is");
    for (int i = 0; i < 3; i++) {
        printf(" %d", reversed[i]);
    }
    
    return 0;
}
```
### 5. cp4h_04
```c=
#include <stdio.h>

int main(){
    int decimalNumber;
    int octalNumber = 0;
    int octalDigit, placeValue = 1;

    printf("Enter a number between 0 and 32767:");
    scanf("%d", &decimalNumber);

    while (decimalNumber > 0){
            octalDigit = decimalNumber % 8;
            octalNumber = octalDigit * placeValue + octalNumber;
            decimalNumber /= 8;
            placeValue *= 10;
    }

    printf("In octal, your number is:%05d", octalNumber);

    return 0;
}
```
### 6. cp4h_05
```c=
#include <stdio.h>

int main(){
    int upc[11]; 
    int i, sum1, sum2, total;
    printf("Enter the first 11 digits of a UPC:");
    for (i = 0; i < 11; i++){
        scanf("%1d", &upc[i]);
    }
    sum1 = upc[0] + upc[2] + upc[4] + upc[6] + upc[8] + upc[10];
    sum2 = upc[1] + upc[3] + upc[5] + upc[7] + upc[9];
    total = 3 * sum1 + sum2;
    
    int check_digit = 9 - ((total - 1) % 10);

    printf("Check digit:%d", check_digit);

    return 0;
}
```
### 7. cp4h_06
```c=
#include<stdio.h>
int main(){
    int ean[12]; 
    int i, sum1 = 0, sum2 = 0, total;
    printf("Enter the first 12 digits of an EAN:");
    for (i = 0; i < 12; i++){
        scanf("%1d", &ean[i]);
    }
    
    for (i = 0; i < 12; i++){
        if (i % 2 == 0) {
            sum1 += ean[i];
        } else {
            sum2 += ean[i];
        }
    }
    
    total = sum1 + sum2 * 3;
    int check_digit = 10 - (total % 10);

    printf("Check digit:%d", check_digit);

    return 0;
}
```
ch05_上課練習
---
### 1. ch05_Calculating a Broker's Commission
```c=
#include <stdio.h>

int main() {
    double value_of_trade;
    double commission = 0.0;

    printf("Enter value of trade: ");
    scanf("%lf", &value_of_trade);

    if (value_of_trade < 2500.0) {
        commission = 30.00 + (0.017 * value_of_trade);
    } else if (value_of_trade >= 2500.0 && value_of_trade < 6250.0) {
        commission = 56.00 + (0.0066 * value_of_trade);
    } else if (value_of_trade >= 6250.0 && value_of_trade < 20000.0) {
        commission = 76.00 + (0.0034 * value_of_trade);
    } else if (value_of_trade >= 20000.0 && value_of_trade < 50000.0) {
        commission = 100.00 + (0.0022 * value_of_trade);
    } else if (value_of_trade >= 50000.0 && value_of_trade <= 500000.0) {
        commission = 155.00 + (0.0011 * value_of_trade);
    } else {
        commission = 255.00 + (0.0009 * value_of_trade);
    }

    if (commission < 39.00) {
        commission = 39.00;
    }

    printf("Commission: $%.2lf", commission);

    return 0;
}
```
### 2. ch05_Calculating a Broker's Commission2
```c=
#include <stdio.h>

int main() {
    double value_of_trade;
    double commission = 0.0;

    printf("Enter value of trade: ");
    scanf("%lf", &value_of_trade);

    if (value_of_trade < 2000.0) {
        commission = 50.00 + (0.02 * value_of_trade);
    } else if (value_of_trade >= 2000.0 && value_of_trade < 6000.0) {
        commission = 80.00 + (0.015 * value_of_trade);
    } else if (value_of_trade >= 6000.0 && value_of_trade < 20000.0) {
        commission = 110.00 + (0.01 * value_of_trade);
    } else if (value_of_trade >= 20000.0 && value_of_trade < 55000.0) {
        commission = 180.000 + (0.005 * value_of_trade);
    } else if (value_of_trade >= 55000.0 && value_of_trade < 1000000.0) {
        commission = 200.00 + (0.0015 * value_of_trade);
    } else  {
        commission = 250.00 + (0.0009 * value_of_trade);
    }

    if (commission < 70.00) {
        commission = 70.00;
    }

    printf("Commission: $%.2lf", commission);

    return 0;
}
```
### 3. ch05_07
```c=
#include <stdio.h>

int main() {
    float num,price;
    
    printf("Enter the number of shares: ");
    scanf("%f", &num);
    
    printf("Enter price per share: ");
    scanf("%f", &price);
    
    float value = num * price;

    float original;
    if (value < 2500.0f) {
        original = 30.0f + 0.017f * value;
    } else if (value < 6250.0f) {
        original = 56.0f + 0.0066f * value;
    } else if (value < 20000.0f) {
        original = 76.0f + 0.0034f * value;
    } else if (value < 50000.0f) {
        original = 100.0f + 0.0022f * value;
    } else if (value < 500000.0f) {
        original = 155.0f + 0.0011f * value;
    } else {
        original = 255.0f + 0.0009f * value;
    }
    
    float rival;
    if (num < 2000) {
        rival = 33.0f + 0.03f * num;
    } else {
        rival = 33.0f + 0.02f * num;
    }
    
    printf("Original broker's commission: $%.2f\n", original);
    printf("Rival broker's commission: $%.2f", rival);
    
    return 0;
}
```
### 4. ch05_Printing a Date in Legal Form
```c=
#include <stdio.h>
#include <string.h>

int main() {
    int m, d, y;
    char mon[20];
    char day[3];  

    printf("Enter date (mm/dd/yy): ");
    scanf("%2d/%2d/%2d", &m, &d, &y);

    if (m == 1) {
        strcpy(mon, "January");
    } else if (m == 2) {
        strcpy(mon, "February");
    } else if (m == 3) {
        strcpy(mon, "March");
    } else if (m == 4) {
        strcpy(mon, "April");
    } else if (m == 5) {
        strcpy(mon, "May");
    } else if (m == 6) {
        strcpy(mon, "June");
    } else if (m == 7) {
        strcpy(mon, "July");
    } else if (m == 8) {
        strcpy(mon, "August");
    } else if (m == 9) {
        strcpy(mon, "September");
    } else if (m == 10) {
        strcpy(mon, "October");
    } else if (m == 11) {
        strcpy(mon, "November");
    } else {
        strcpy(mon, "December");
    }

    if (d == 1 || d == 21 || d == 31) {
        strcpy(day, "st");  
    } else if (d == 2 || d == 22) {
        strcpy(day, "nd");  
    } else if (d == 3 || d == 23) {
        strcpy(day, "rd");      
    } else {
        strcpy(day, "th"); 
    }

    printf("Dated this %d%s day of %s, 20%d.", d, day, mon, y);

    return 0;
}
```
### 5. Printing date and time in Legal Form(上課延伸)
```c=
#include <stdio.h>
#include <string.h>

int main() {
    int month, day1 , year, hour, minute, second;
    char am_pm[3];
    char day2[3];

    scanf("%d/%d/%d", &month, &day1, &year);

    scanf("%d:%d:%d", &hour, &minute, &second);

    if (hour >= 12) {
        strcpy(am_pm, "PM");
        if (hour > 12) {
            hour -= 12;
        }
    } else {
        strcpy(am_pm, "AM");
        if (hour == 0) {
            hour = 12;
        }
    }

    if (day1 == 1 || day1 == 21 || day1 == 31) {
        strcpy(day2, "st");  
    } else if (day1 == 2 || day1 == 22) {
        strcpy(day2, "nd");  
    } else if (day1 == 3 || day1 == 23) {
        strcpy(day2, "rd");      
    } else {
        strcpy(day2, "th"); 
    }

    char month_name[12][15] = {
        "January", "February", "March", "April", "May", "June",
        "July", "August", "September", "October", "November", "December"
    };

    printf("%s %02d:%02d:%02d, %d%s day of %s, 20%02d.", am_pm, hour, minute, second, day1, day2, month_name[month - 1], year);

    return 0;
}
```
### 6. ch05_Printing a Date in Legal Form2
```c=
#include<stdio.h>

int main(void){
	int h,m,a,b;
	scanf("%d",&a);
	h=a/60;
    m=a%60;
    b=h%12;
    if(h<12 || h==24)
        printf("AM:");
    else 
        printf("PM:");
    switch(b)
    {
        case 0:
            printf("twelve:");
            break;
        case 1:
            printf("one:");
            break;
        case 2:
            printf("two:");
            break;
        case 3:
            printf("three:");
            break;
        case 4:
            printf("four:");
            break;
        case 5:
            printf("five:");
            break;
        case 6:
            printf("six:");
            break;
        case 7:
            printf("seven:");
            break;
        case 8:
            printf("eight:");
            break;
        case 9:
            printf("nine:");
            break;
        case 10:
            printf("ten:");
            break;
        case 11:
            printf("eleven:");
            break;
    }
    printf("%d",m);

	return 0;
}
``` 
ch05_Homework
---
### 1. ch5_01
```c=
#include <stdio.h>
#include <string.h>

int main() {
    int m;
    char mon[20];

    scanf("%d", &m );

    if (m == 1) {
        strcpy(mon, "January");
    } else if (m == 2) {
        strcpy(mon, "February");
    } else if (m == 3) {
        strcpy(mon, "March");
    } else if (m == 4) {
        strcpy(mon, "April");
    } else if (m == 5) {
        strcpy(mon, "May");
    } else if (m == 6) {
        strcpy(mon, "June");
    } else if (m == 7) {
        strcpy(mon, "July");
    } else if (m == 8) {
        strcpy(mon, "August");
    } else if (m == 9) {
        strcpy(mon, "September");
    } else if (m == 10) {
        strcpy(mon, "October");
    } else if (m == 11) {
        strcpy(mon, "November");
    } else if (m == 12) {
        strcpy(mon, "December");
    } else {
        strcpy(mon, "error");
    }

    printf("%s", mon );

    return 0;
}
```
### 2. ch5_02
```c=
#include <stdio.h>
#include <string.h>

int main() {
    char m;
    char a[10];

    scanf("%c", &m );

    if (m == 'A' || m == 'a' ) {
        strcpy(a, "Apple");
    } else if (m == 'B' || m == 'b') {
        strcpy(a, "Banana");
    } else if (m == 'C' || m == 'c') {
        strcpy(a, "Cherry");
    } else if (m == 'D' || m == 'd') {
        strcpy(a, "Durian");
    } else if (m == 'E' || m == 'e') {
        strcpy(a, "Egg");
    } else if (m == 'F' || m == 'f') {
        strcpy(a, "Fish");
    } else {
        strcpy(a, "Error");
    }

    printf("%s", a );

    return 0;
}
```
### 3. cp5_01_broker
```c=
#include <stdio.h>

int main(void){
float commission, value;  
printf("Enter value of trade: ");
scanf("%f", &value);
if (value < 2500.00f) 
  commission = 30.00f + .017f * value;
else if (value < 6250.00f)
  commission = 56.00f + .0066f * value;
else if (value < 20000.00f)
  commission = 76.00f + .0034f * value;
else if (value < 50000.00f)
  commission = 100.00f + .0022f * value;
else if (value < 500000.00f)
  commission = 155.00f + .0011f * value;
else
  commission = 255.00f + .0009f * value;
if (commission < 39.00f)
  commission = 39.00f;
printf("Commission: $%.2f", commission);

return 0;
}
```
### 4. cp5_02_date
```c=
#include <stdio.h>

int main(void){
int month, day, year;

printf("Enter date (mm/dd/yy): ");
scanf("%d /%d /%d", &month, &day, &year);
printf("Dated this %d", day);

switch (day) {
    case 1: case 21: case 31:
    printf("st"); 
    break;
    case 2: case 22:
    printf("nd"); 
    break;
    case 3: case 23:
    printf("rd"); 
    break;
    default: 
    printf("th"); 
    break;
}
printf(" day of ");
switch (month) {
    case 1:  
    printf("January");   
    break;
    case 2:  
    printf("February");  
    break;
    case 3:  
    printf("March");
    break;
    case 4:
    printf("April");
    break;
    case 5:  
    printf("May");
    break;
    case 6:  
    printf("June");
    break;
    case 7:  
    printf("July");
    break;
    case 8:  
    printf("August");
    break;
    case 9:  
    printf("September"); 
    break;
    case 10: 
    printf("October");   
    break;
    case 11: 
    printf("November");  
    break;
    case 12: printf("December");  
    break;
}
printf(", 20%.2d.\n", year);

return 0; 
}
```
### 5. cp5h_01
```c=
#include <stdio.h>
#include <string.h>

#define NUM 10

int main() {
    char input[NUM];
    int count = 0;
    int nonZeroFound = 0;

    printf("Enter a number: ");
    scanf("%s", input);

    for (int i = 0; i < NUM; i++) {
        if (input[i] != '\0' && input[i] != ' ' && input[i] != '-') {
            if (input[i] != '0' || nonZeroFound) {
                count += 1;
                nonZeroFound = 1;
            }
        } else {
            break;
        }
    }

    if (count > 4 || count == 0) {
        printf("Please enter the whole between 1 and 9999");
    } else if (count == 1) {
        printf("The number %.*s has 1 digit", count, input);
    } else {
        printf("The number %.*s has %d digits", count, input, count);
    }

    return 0;
}
```
### 6. cp5h_02
```c=
#include <stdio.h>

int main() {
    int hours, minutes;

    printf("Enter a 24-hour time: ");
    scanf("%d:%d", &hours, &minutes);

    if (hours >= 0 && hours <= 23 && minutes >= 0 && minutes <= 59) {
        if (hours < 12) {
            if (hours == 0) {
                printf("Equivalent 12-hour time: 12:%02d AM", minutes);
            } else {
                printf("Equivalent 12-hour time: %d:%02d AM", hours, minutes);
            }
        } else if (hours == 12) {
            printf("Equivalent 12-hour time: 12:%02d PM", minutes);
        } else {
            printf("Equivalent 12-hour time: %d:%02d PM", hours - 12, minutes);
        }
    } else {
        printf("Not the correct time format");
    }

    return 0;
}

```
### 7. ch05_07
```c=
#include<stdio.h>

int main(void){
	float c,v,a,b,d;
	printf("Enter the number of shares: ");
	scanf("%f",&a);
	printf("Enter price per share: ");
	scanf("%f",&b);
	v=a*b;
	if(v<2500.00f)
		c=30.00f+.017f*v;
	else if(v<6250.00f)
		c=56.00f+.0066f*v;
	else if(v<20000.00f)
		c=76.00f+.0034f*v;
	else if(v<50000.00f)
		c=100.00f+.0022f*v;
	else if(v<500000.00f)
		c=155.00f+.0011f*v;
	else
		c=255.00f+.0009f*v;
	if(c<39.00f)
		c=39.00f;
	if(a<2000)
		d=33.00f+.03f*a;
	else
		d=33.00f+.02f*a;
	printf("Original broker's commission: $%.2f\n",c);
	printf("Rival broker's commission: $%.2f",d);

	return 0;
}
```
### 8. cp5h_04
```c=
#include <stdio.h>

int main() {
    int speed;

    printf("Enter wind speed (knots): ");
    scanf("%d", &speed);

    if (speed < 1) {
        printf("Wind force at %d knots is Calm", speed);
    } else if (speed >= 1 && speed <= 3) {
        printf("Wind force at %d knots is Light air", speed);
    } else if (speed >= 4 && speed <= 27) {
        printf("Wind force at %d knots is Breeze", speed);
    } else if (speed >= 28 && speed <= 47) {
        printf("Wind force at %d knots is Gale", speed);
    } else if (speed >= 48 && speed <= 63) {
        printf("Wind force at %d knots is Storm", speed);
    } else {
        printf("Wind force at %d knots is Hurricane", speed);
    }

    return 0;
}
```
### 9. cp5h_05
```c=
#include <stdio.h>

int main() {
    double income, tax;

    printf("Enter amount of taxable income: ");
    scanf("%lf", &income);

    if (income <= 750) {
        tax = income * 0.01;
    } else if (income <= 2250) {
        tax = 7.50 + (income - 750) * 0.02;
    } else if (income <= 3750) {
        tax = 37.50 + (income - 2250) * 0.03;
    } else if (income <= 5250) {
        tax = 82.50 + (income - 3750) * 0.04;
    } else if (income <= 7000) {
        tax = 142.50 + (income - 5250) * 0.05;
    } else {
        tax = 230.00 + (income - 7000) * 0.06;
    }

    printf("Tax due is: $%.2lf", tax);

    return 0;
}
```
### 10. cp5h_06
```c=
#include <stdio.h>

int main() {
    int grade;
    char letter;

    printf("Enter a numerical grade: ");
    scanf("%d", &grade);

    if (grade >= 0 && grade <= 100) {
        switch (grade / 10) {
            case 10:
            case 9:
                letter = 'A';
                break;
            case 8:
                letter = 'B';
                break;
            case 7:
                letter = 'C';
                break;
            case 6:
                letter = 'D';
                break;
            default:
                letter = 'F';
                break;
        }

        printf("Letter grade: %c", letter);
    } else {
        printf("Invalid grade. Please enter a grade between 0 and 100.");
    }

    return 0;
}
```
### 11. 畢氏定理
```c=
#include <stdio.h>

int main() {
    int a, b, c;

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

    if (a > b && a > c) {
        printf("%d", a);
    } else if (b > a && b > c) {
        printf("%d", b);
    } else {
        printf("%d", c);
    }

    return 0;
}
```
### 12. 畢氏定理2
```c=
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    if (a > 0 && b > 0 && c > 0) {
        if (a * a == b * b + c * c || b * b == a * a + c * c || c * c == a * a + b * b) {
            printf("%d", a > b ? (a > c ? a : c) : (b > c ? b : c));
        } else {
            printf("0");
        }
    } else {
        printf("0");
    }

    return 0;
}
```
ch06_上課練習
---

### 1. ch06_Printing a Table of Squares_1
```c=
#include<stdio.h>
int main(){
    int n=10;
    int i=1;
    while(i< n){
        i *= 3;
        printf("%d\n",i);
    }

    return 0;
}
```
### 2. ch06_Printing a Table of Squares_2
```c=
#include<stdio.h>
int main(){

    int i=1;
    int num=0;
    while(i<=10){
        num += i;
        i++;
    }

    printf("%d",num);

    return 0;
}
```
### 3. ch06_Printing a Table of Squares_3
```c=
#include<stdio.h>
int main(){

    int i=1;
    int num=0;
    int n=0;
    scanf("%d",&n);

    while(i<=n){
        num += i;
        i++;
    }

    printf("%d",num);

    return 0;
}
```
### 4. ch06_Printing a Table of Squares
```c=
#include<stdio.h>
int main(){

    int i=1;
    int n=0;
    printf("Enter number of entries in table: ");
    scanf("%d",&n);

    while(i<=n){
        printf("%10d%10d\n",i,i*i);
        i++;
    }

    return 0;
}
```
### 5. ch06_Printing a Table of Squares
```c=
#include<stdio.h>
int main(){

    int num=0;

    printf("Enter number of entries in table: ");
    scanf("%d",&num);

    for (int i = 1; i <= num ;i++){
        printf("%10d%10d\n",i,i*i);
    }
    
}
```
### 6. ch06_Printing a Table of Squares
```c=
#include<stdio.h>
int main(){

    int i=1;
    int n=0;
    printf("Enter number of entries in table: ");
    scanf("%d",&n);

    while(i<=n){
        printf("%10d%10d%10d\n",i,i*2,i*3);
        i++;
    }

    return 0;
}
```
### 7. ch06_03
```c=
#include<stdio.h>
int main(){

    int i=0;
    int n=0;

    printf("Enter integers (0 to terminate): ");

    do{
        scanf("%d",&n);
        i += n;
    }while(n!=0);

    printf("The sum is: %d",i);

    return 0;
}
```
### 8. ch06_04
```c=
#include<stdio.h>
int main(){

    int i=0;
    int n=0;

    printf("Enter a nonnegative integer: ");
    scanf("%d",&n);

    do{
        n /= 10;
        i += 1;
    }while(n!=0);

    printf("The number has %d digit(s).",i);

    return 0;
}
```
### 9. cp02-02_print
```c=
#include<stdio.h>
int main(){
    printf("    *\n");
    printf("   ***\n");
    printf("  *****\n");
    printf(" *******\n");
    printf("  *****\n");
    printf(" *******\n");
    printf("*********\n");
    printf("    *\n");
    printf("    *\n");

    return 0;    
}
#include<stdio.h>
int main(){

    int i=0;
    int n=0;

    printf("Enter a nonnegative integer: ");
    scanf("%d",&n);

    do{
        i += n%10;
        n = (n-n%10)/10;
    }while(n!=0);

    printf("%d",i);

    return 0;
}
```
### 10. ch06_04_2
```c=
#include<stdio.h>
int main(){

    int i=0;
    int n=0;

    printf("Enter a nonnegative integer: ");
    scanf("%d",&n);

    do{
        i += n%10;
        n = (n-n%10)/10;
    }while(n!=0);

    printf("%d",i);

    return 0;
```
### 11. ch06_05_1
```c=
#include<stdio.h>
int main(){
    int num=0;
    printf("Enter number of entries in table: ");
    scanf("%d",&num);

    for(int i=1;i<=num;i++){
        printf("%10d%10d\n",i,i*i);
    }

    return 0;
}
```
### 12. ch06_05_2
```c=
#include <stdio.h>

int main(){
    int num=0;
    scanf("%d",&num);

    for(int i=1;i<=num;i++){
        for(int j=1;j<=i;j++){
            printf("*");
        }
        if(i!=num) printf("\n");
    }

    return 0;
}
```
### 13. ch06_06
```c=
#include<stdio.h>
int main(){
    int num=0;
    float credit=0;

    printf("*** ACME checkbook-balancing program ***\n");
    printf("Commands: 0=clear, 1=credit, 2=debit, 3=balance, 4=exit\n");
    printf("\n");    

    for(int i=1;i>0;i++){
        float j=0;
        num =0;
        printf("Enter command: ");
        scanf("%d",&num);

        if(num==1){
            printf("Enter amount of credit: ");
            scanf("%f",&j);
            credit += j;
        }

        if(num==2){
            printf("Enter amount of debit: ");
            scanf("%f",&j);
            credit -= j;
        }

        if(num==3){
            printf("Current balance: $%.2f\n",credit);
        }
        if(num==4) break; 
    }

    return 0;
}
```
ch06_Homework
---

### 1.HW_01

```c=
#include <stdio.h>
int main(){

    float a,max=0;
    printf("Enter a number (enter 0 to end): ");
    scanf("%f",&a);
    while (a != 0){
        printf("Enter a number (enter 0 to end): ");
        scanf("%f",&a);
        if(a>max){
            max = a;
        }
    }
    printf("The largest number entered was %.2f",max);
    
    return 0;
}
```


### 2.HW_02
```c=
#include <stdio.h>
int main(){

    int a,b,c; // a為被除數 b為除數 c為餘數
    int temp;
    int gcd;
    printf("Enter two integers: ");
    scanf("%d %d",&a,&b);

    // 利用輾轉相除法
    if(a<b){
        temp = a;
        a = b;
        b = temp;
    }
    c = a % b;
    
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    gcd = b;

    printf("Greatest common divisor: %d",gcd);
    return 0;
}
```

### 3.CH6_01
```c=
#include <stdio.h>
int main(){

    int i=1,n;
    printf("This program prints a table of squares.\n");
    printf("Enter number of entries in table: ");
    scanf("%d",&n);

    while (i <= n){
        printf("%10d%10d\n",i,i*i);
        i++;
    }

    return 0;
}
```

### 4.HW_03
```c=
#include <stdio.h>
int main(){

    int a;
    printf("Enter a number: ");
    scanf("%d",&a);
    for(int i=2;i*i<=a;i+=2){
        printf("%d\n",i*i);
    }

    return 0;
}
```

### 5.HW_04
```c=
#include <stdio.h>
int main(){

    int a;
    scanf("%d",&a);
    for(int i=1;i<=a;i++){
        for(int j=0;j<i;j++){
            printf("*");
        }
        if(i<a){
            printf("\n");
        }
    }


    return 0;
}
```

### 6.HW_05
```c=
#include <stdio.h>
int main(){

    int a,ans,count=0;
    int min=0,max=100;

    printf("Enter the answer number(0-100): ");
    printf("\n");
    scanf("%d",&ans);
    printf("Game start!\n");
    printf("\n");

    while(a != ans){
        printf("Enter a number(%d-%d): ",min,max);
        scanf("%d",&a);
        printf("\n");
        if(a>ans){
            if(count>0){
                if(a>max){
                    max = max;
                }
                else{
                    max = a;
                }
            }
            else{
                max = a;
            }
        }
        else if(a<ans){
            if(count>0){
                if(a<min){
                    min = min;
                }
                else{
                    min = a;
                }
            }
            else{
                min = a;
            }
        }
        count++;
    }

    printf("BANG!");
    
    return 0;
}
```

### 7.ch_06
```c=
#include <stdio.h>
int main(){

    int n,sum=0;
    printf("This program sums a series of integers.\n");
    printf("Enter integers (0 to terminate): ");
    scanf("%d",&n);
    while(n != 0){
        sum += n;
        scanf("%d",&n);
    }
    printf("The sum is: %d\n",sum);

    return 0;
}
```

### 8.HW_06
```c=
#include <stdio.h>
int main(){

    int a,b,c,gcd,temp;
    printf("Enter a fraction (x/y): \n");
    scanf("%d/%d",&a,&b);
    int d = a, e = b;

    if(a<b){
        temp = a;
        a = b;
        b = temp;
    }
    c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    gcd = b;

    d /= gcd;
    e /= gcd;

    printf("GCD = %d\nIn lowest terms: %d/%d",gcd,d,e);
    return 0;
}
```

### 9. ch06_continue&break
```c=
#include <stdio.h>
int main(){

    int a,sum=0;
    
    while(1){
        scanf("%d",&a);
        if(a == 0){
            break;
        }
        if(a>0){
            sum += a;
        }
        else if(a<0){
            continue;
        }
    }
    printf("%d",sum);
    return 0;
}
```
### 10. ch6_03
```c=
#include<stdio.h>
int main(){

    int i=0;
    int n=0;

    printf("Enter a nonnegative integer: ");
    scanf("%d",&n);

    do{
        n /= 10;
        i += 1;
    }while(n!=0);

    printf("The number has %d digit(s).",i);

    return 0;
}
```
### 11. ch6_hw_07
```c=
#include<stdio.h>
int main(){
    int i=2,n=0;

    scanf("%d",&n);
    printf("\n");

    while(i<=n){

        if(i*i<=n) printf("%d",i*i);
        else break;

        if(i*i==n) break;

        if((i+2)*(i+2)<=n){
            printf("\n");
        }

        i+=2;
    }

    return 0;
}
```
### 12. ch6_hw_08
```c=
#include<stdio.h>
int main(){

    int day,start;

    scanf("%d",&day);
    scanf("%d",&start);
    printf("\n");

    start -=1;

    for (int i = 0; i < start*3; i++){
        printf(" ");
    }
    

    for (int i = 1; i <= day; i++){

        if(i==day){

            printf("%2d",i);

            break;
        }

        if((start +i)%7==0){

            printf("%2d",i);
            printf("\n");

            continue;
        }

        printf("%2d ",i);
 
    }
    

}
```
### 13. ch6_04
```c=
#include<stdio.h>
int main(){
    int i,n;
    printf("This program prints a table of squares.\n");
    printf("Enter number of entries in table:");
    scanf("%d",&n);
    printf("\n");

    i = 1;
    while(i<=n){
        printf("%10d%10d\n",i,i *i);
        if(i==n) break;
        i++;
    }
    return 0;
}
```
### 14. ch6_hw_09
```c=
#include<stdio.h>
int main(){
    float ans=0,num=0,temp=1;
    scanf("%f",&num);
    
    for (float i = 1; i <= num+1; i++){
        temp = 1;

        for (float j = 1; j <= i; j++){
            temp *= j;
        }
        ans += i/temp;
    }

    printf("%.4f",ans);
    
}
``` 
### 15. ch6_05
```c=
#include<stdio.h>
int main(){
    int i,n,odd;
    printf("\nThis program prints a table of squares.\n");
    printf("Enter number of entries in table:");
    scanf("%d",&n);
    printf("\n");

    i = 1;
    odd= 3;

    for (int s = 1; i <= n; odd+=2){
        printf("%10d%10d\n", i,s);
        i++;
        s += odd;
    }
    
    return 0;
}
```
### 16. ch6_06
```c=
#include<stdio.h>
int main(){
    int num=0;
    float credit=0;

    printf("*** ACME checkbook-balancing program ***\n");
    printf("Commands: 0=clear, 1=credit, 2=debit, 3=balance, 4=exit\n\n");

    for(int i=1;i>0;i++){
        float j=0;
        num =0;
        printf("Enter command: \n");
        scanf("%d",&num);

        if(num==0){
            credit =0;
        }
        if(num==1){
            printf("Enter amount of credit: \n");
            scanf("%f",&j);
            credit += j;
        }

        if(num==2){
            printf("Enter amount of debit: \n");
            scanf("%f",&j);
            credit -= j;
        }

        if(num==3){
            printf("Current balance: $%.2f\n",credit);
        }
        if(num==4) break; 
    }

    return 0;
}
```
ch6_課堂練習
---
### 1. ch6_Printing a Table of Squares_01
```c=
#include <stdio.h>

int main() {
    int m, n, remainder;

    printf("Enter two integers: ");
    scanf("%d %d", &m, &n);

    while (n != 0) {
        remainder = m % n;
        m = n;
        n = remainder;
    }

    printf("Greatest common divisor: %d", m);

    return 0;
}
```
### 2. ch6_Printing a Table of Squares_02
```c=
#include<stdio.h>
int main(){

    int ans=0,big=100,small=0,num=-1;

    printf("Enter the answer number(0-100):");
    scanf("%d",&ans);
    printf("\n");

    printf("Game start!\n\n");
    
    while(num!=ans){

        printf("Enter a number(%d-%d):",small,big);
        scanf("%d\n",&num);
        printf("\n");

      if(num<=small && num<=ans && num>0)
            small = num;

        else if(num>=small && num<=ans)
            small = num;

        else if(num>=small && num>=ans)
            big = num;
    }

    printf("BANG!");
}
```
### 3. ch6_Printing a Table of Squares_03
```c=

```
ch07_上課練習
---
### 1. ch07_01
```c=
#include<stdio.h>
int main(){
    long a=-1,b=0;

    while(a!=0){
        scanf("%ld",&a);
        b +=a;
    }

    printf("%ld",b);
    return 0;
}
```
### 2. ch07_02
```c=
#include<stdio.h>
int main(){
    char c;
    int a=0;

    printf("Enter a message:");
    while(c!='\n'){
        scanf("%c",&c);
        a +=1;
    }

    printf("Your message was %d character(s) long.",a-1);
    return 0;
}
```
ch07_homework
---
### 1. ch07_hw_01
```c=
#include<stdio.h>
int main(){

    char a[14];

    printf("Enter phone number: ");
    scanf("%s",a);

    for (int i = 0; i < 14; i++){
        if(a[i]>='A' && a[i]<='C'){
            a[i] = '2';
        }
        
        if(a[i]>='D' && a[i]<='F'){
            a[i] = '3';
        }

        if(a[i]>='G' && a[i]<='I'){
            a[i] = '4';
        }

        if(a[i]>='J' && a[i]<='L'){
            a[i] = '5';
        }

        if(a[i]>='M' && a[i]<='O'){
            a[i] = '6';
        }

        if(a[i]>='P' && a[i]<='S'){
            a[i] = '7';
        }

        if(a[i]>='T' && a[i]<='V'){
            a[i] = '8';
        }

        if(a[i]>='W' && a[i]<='Y'){
            a[i] = '9';
        }

        if(a[i]>='a' && a[i]<='C'){
            a[i] = '2';
        }
    }

    printf("%s",a);
    
}
```
### 2. ch07_hw_02
```c=
#include<stdio.h>
int main(){
    char c;
    int a=0;

    printf("Enter a word:");

    while(c!='\n'){
        scanf("%c",&c);
        
        //轉小寫
        if(c<='Z' && c>='A'){
            c +=32;
        }

        if(c=='a' || c=='e' || c=='i' || c=='l' || c=='n' || c=='o' || c=='r' || c=='s'
        || c=='t' || c=='u'){
            a +=1;
        }

        if(c =='d' || c == 'g'){
            a+=2;
        }

        if(c=='b' || c=='c' || c=='m' || c=='p'){
            a+=3;
        }

        if(c=='f' || c=='h' || c=='v' || c=='w' ||c=='y'){
            a+=4;
        }

        if(c=='k'){
            a+=5;
        }

        if(c=='j' || c=='x'){
            a+=8;
        }

        if(c=='q' || c=='z'){
            a+=10;
        }
    }

    printf("\nScrabble value: %d",a);

}
```
### 3. ch07_hw_03
```c=
#include<stdio.h>
int main(){
    char c;
    int a=0;

    printf("Enter a word:");

    while(c!='\n'){
        scanf("%c",&c);
        
        //轉小寫
        if(c<='Z' && c>='A'){
            c +=32;
        }

        if(c=='a' || c=='e' || c=='i' || c=='l' || c=='n' || c=='o' || c=='r' || c=='s'
        || c=='t' || c=='u'){
            a +=1;
        }

        if(c =='d' || c == 'g'){
            a+=2;
        }

        if(c=='b' || c=='c' || c=='m' || c=='p'){
            a+=3;
        }

        if(c=='f' || c=='h' || c=='v' || c=='w' ||c=='y'){
            a+=4;
        }

        if(c=='k'){
            a+=5;
        }

        if(c=='j' || c=='x'){
            a+=8;
        }

        if(c=='q' || c=='z'){
            a+=10;
        }
    }

    printf("\nScrabble value: %d",a);

}
```
### 4. ch07_hw_04
```c=
#include<stdio.h>
int main(){

    char c;
    int a=0;

    printf("Enter a sentence: ");

    while(c!='\n'){
        scanf("%c",&c);
        
        if(c<='Z' && c>='A'){
            c +=32;
        }

        if(c == 'a'|| c=='e' || c=='i' || c=='o' || c=='u') a+=1;
    }

    printf("\nYour sentence contains %d vowels.",a);
}
```
### 5. ch07_hw_05
```c=
#include <stdio.h>

int main(void) {
    char name[2][50]; 

    printf("Enter a first and last name: ");
    scanf("%s %s", name[0], name[1]);

    printf("%s, %c.", name[1], name[0][0]); 

    return 0;
}
```
### 6. ch07_hw_06
```c=
#include<stdio.h>
int main(){
    char a,b;
    float x,y,z;

    printf("Enter an expression (example: 1+2.5*3):  ");
    scanf("%f%c%f%c%f",&x,&a,&y,&b,&z);

    if(a=='+') x += y;
    else if(a=='-') x -= y;
    else if(a=='*') x *= y;
    else x /= y;

    if(b=='+') x += z;
    else if(b=='-') x -= z;
    else if(b=='*') x *= z;
    else x /= z;

    printf("Value of expression: %.1f",x);

}
```
### 7. ch07_hw_07
```c=
#include<stdio.h>
int main(){
    char c;
    float len=0,a=0,w=0;

    printf("Enter a sentence: ");

    while(c!='\n'){
        scanf("%c",&c);
        if(c==' ' || c=='\n'){
            w +=1;
            continue;;
        }
        a +=1;
        if(c==' ') w +=1;
    }

    len = a/w;

    printf("Characters: %.0f\n",a);
    printf("Words: %.0f\n",w);
    printf("Average word length: %.1f",len);

}
```
### 8. ch07_hw_08

```c=
#include <stdio.h>
#include <math.h>

int main() {
    double x;
    double guess = 1.0, new_guess;

    printf("Enter a positive number: ");
    scanf("%lf", &x);

    do {
        new_guess = (guess + x / guess) / 2;
        if (fabs(new_guess - guess) < 0.00001) {
            guess = new_guess;
            break;
        }
        guess = new_guess;
    } while (1);

    printf("Square root: %.5f", guess);

    return 0;
}
```
ch08_上課練習
---
### 1. CH08_Arrays_01
```c=
#include<stdio.h>

int main () {
    int input[5];
    scanf("%d %d %d %d %d",&input[0],&input[1],&input[2],&input[3],&input[4]);
    for (int i = 0; i < 5; i++)
    {
        printf("%d\n",input[i]);
    }
    
    return 0;
}
```
### 2. CH08_Arrays_Reversing a Series of Numbers
```c=
#include<stdio.h>

int main () {
    int input [10] , i;
    for ( i = 0; i < 10; i++)
    {
        scanf("%d",&input[i]);
    }
    for ( i = 9; i > 0; i--)
    {
        printf("%d ",input[i]);
    }
    printf("%d", input[0]);
    
    return 0;
}
```
### 3. CH08_Arrays_01
```c=
#include<stdio.h>

int main () {
    int input[5];
    scanf("%d %d %d %d %d",&input[0],&input[1],&input[2],&input[3],&input[4]);
    for (int i = 0; i < 5; i++)
    {
        printf("%d\n",input[i]);
    }
    
    return 0;
}
```
### 4. CH08_Arrays_Reversing a Series of Numbers
```c=
#include<stdio.h>

int main () {
    int input [10] , i;
    for ( i = 0; i < 10; i++)
    {
        scanf("%d",&input[i]);
    }
    for ( i = 9; i > 0; i--)
    {
        printf("%d ",input[i]);
    }
    printf("%d", input[0]);
    
    return 0;
}
```
### 5. ch08_03
```c=
#include<stdio.h>

int main () {
    int number , count = 0 , check;
    printf("Enter a number: ");
    scanf("%d", &number );
    check = number;
    while (check != 0){
        check/=10;
        count++;
    }
    int num [count];
    for (int i = count - 1 ; i >=0 ; i--){
        num[i] = number % 10;
        number/=10;
    }
    int judge = 1;
    for (int i = 0 ; i < count ; i++ ){
        for (int j = i + 1 ; j < count; j++)
        {
            if(num[i] == num[j])
                judge = 0;
        }
    }
    if ( judge == 1 ){
        printf("No repeated digit");
    }
    else{
        printf("Repeated digit");
    }

    return 0;
}
```