MMGames Introduction to C C Language Development Environment C language now Useful Apps Contact Us
MMGames

Automatic version identification

SpineViewer

It's easy to tell by looking at it.

Response Time Checker

I can leave my computer on and do it.

Mouse cleaning time

I can leave my computer on and do it.

Mouse cleaning time

C language learned by suffering
C language learned by suffering

Exercise 8

fundamental knowledge

Q1-1
What is the option to add a statement to the if statement to be executed when the condition is false?


Q 1-2
What is commonly called a writing style that uses a combination of several of the above sentences?


Q1-3
What statement is used when you want to separate the statements to be processed by number?

program read-only
What is the next program to display?
Answer by judging from the process contents and variable names.

Q2-1
 #include <stdio.h>

int main(void)
{
    int year;

    scanf("%d", &year);

    if (year % 2 == 0) {
        if (year % 4 == 0) {
            printf("summer\n");
        } else {
            printf("winter\n");
        }
    } else {
        printf("do not\n");
    }

    return 0;
}

program writing

Q3-1
Create a program that displays the corresponding month of the lunar calendar when a month is entered.
Also, display a message when a non-existent month is entered.

Hint: The lunar calendar months are listed in order from January.
Mutsuki, Kisaragi, Yayoi, Ugetsu, Satsuki, Mizunazuki, Bunzuki, Hazuki, Nagatsuki, Kanashizuki, Shimotsuki, Shihatsu

descriptive expression

Q4-1
In a switch statement, why is a break statement placed after each case statement?
Also, briefly explain when this is unnecessary.

Basic Knowledge (sample answers)

Solution 1-1
else statement


Solution 1-2
else-if statement


Solution 1-3
switch statement or switch to case statement

Program reading (example solution)

Solution 2-1
Enter a year in the Western calendar year and it will indicate whether the Olympics will be held or not.

*This program rewrites the problem in the previous chapter with if-else statements.
Program writing (example of solution)

Solution 3-1
 #include <stdio.h>

int main(void)
{
    int month;

    printf("Please enter the month.") ;
    scanf("%d", &month);

    switch (month) {
    case 1:
        printf("睦月\n");
        break;
    case 2:
        printf("如月\n"); break; case 2: printf("如月\n");
        break;
    case 3:
        printf("Yayoi\n");
        break;
    case 4:
        printf("卯月\n"); break; case 4: printf("卯月\n");
        break;
    case 5:
        printf("皐月\n"); break; case 6: printf("皐月\n")
        break;
    case 6:
        printf("水無月\n"); break; case 6: printf("水無月\n")
        break;
    case 7:
        printf("文月\n"); break; case 7: printf("文月\n")
        break;
    case 8:
        printf("葉月\n");
        break;
    case 9:
        printf("長月\n");
        break;
    case 10:
        printf("神無月\n"); break; case 10: printf("神無月\n")
        break;
    case 11:
        printf("霜月\n"); break; case 11: printf("神無月\n")
        break;
    case 12:
        printf("師走\n");
        break;
    default:
        printf("No such month. \n");
        break;
    }

    return 0;
}

The *if statement is also correct, but the switch statement is appropriate for numerous branches by number.
*Points will be deducted if a default statement is missing.
Be careful not to forget the *break statement.
Short Answer Type (Sample Answer)

Solution 4-1
Since the switch statement only has the ability to jump to the corresponding numbered case statement, the
It is necessary to add a break statement so that at the end of each CASE statement, the entire SWITCH statement is left out.
However, only when there is a commonality in the processing of each case statement, it is acceptable to connect them as they are.



About this Site

The C language (bitter C), which is learned by suffering, is
This is the definitive C language introductory site.
It systematically explains the basic functions of the C language and
It is as complete as or more complete than any book on the market.

Part 0: Program Overview
  1. What is the program?
Chapter 2: How to write a program
  1. Writing Rules
  2. Writing conventions
  3. Exercise 2
Chapter 3: Display on Screen
  1. String display
  2. newline character
  3. Exercise 3
Chapter 4: Numeric Display and Calculation
  1. Numeric Display
  2. Basic Calculations
  3. Type of value
  4. Exercise 4
Chapter 5: Numerical Memory and Calculation
  1. Memorize values
  2. Variable Type
  3. Type conversion
  4. Numeric justification
  5. Exercise 5
Chapter 6: Input from the keyboard
  1. Functions for input
  2. Fear of Input
  3. Exercise 6
Chapter 9: Repetition with a fixed number of times
  1. Sentences that repeat themselves
  2. Loop Operation Mechanism
  3. Exercise 9
Chapter 10: Unknown number of repetitions
  1. Loop of unknown frequency
  2. input check
  3. Exercise 10
Chapter 13: Handling Multiple Variables at Once
  1. Multiple variables are handled together.
  2. How to use arrays
  3. Exercise 13
Chapter 19: Dynamic Arrays
  1. Create arrays at will
  2. Exercise 19
Chapter 20: Multiple Source Files
  1. Minimal division
  2. The Stone of Partition
  3. Exercise 20

Comment
COMMENT

Open the 💬 comment submission box