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

Automatic version identification


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 6

fundamental knowledge

What functions are used to enter numbers from the keyboard?

Q 1-2
When using the above functions, what symbol do you put in front of the variable name?

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

 #include <stdio.h>

int main(void)
    int side, high, square;

    scanf("%d,%d", &side, &high);
    square = side * high / 2;
    printf("%d\n", square);

    return 0;

program writing

Create a program that displays a list of prices with 1, 3, 5, and 8 discounts when a fixed price is entered. The resulting amounts should be displayed as integers, but real numbers are also acceptable.

descriptive expression

In fact, the scanf function is rarely used in programs that require reliability.
Briefly explain why this is so.

Basic Knowledge (sample answers)

Solution 1-1
scanf function

*Note that there are many other similar functions that have not yet been introduced.

Solution 1-2

Program reading (example solution)

Solution 2-1
The program calculates the area of a triangle.
The variable names (side, height, area) and the processing details (side x height / 2) indicate this.

If you can somehow guess the reason, even if you cannot give a specific reason, we will assume that you are correct.
*This may have been a bit of a difficult problem.
 However, if you want to continue with the program, you will always be required to read programs written by others.
 Good luck trying to read the program, not only for what it does, but for what it's intended to do!
Program writing (example of solution)

 #include <stdio.h>

int main(void)
    int price;

    printf("Please enter the list price : ");
    scanf("%d", &price);

    printf("1 discount = %d yen\n", (int)(price * 0.9));
    printf("3 discount = %d yen\n", (int)(price * 0.7));
    printf("5 discount = %d Yen\n", (int)(price * 0.5)); printf("5 discount = %d Yen\n", (int)(price * 0.5))
    printf("8 discount = %d yen\n", (int)(price * 0.2));

    return 0;

Execution Result
Please enter the list price : 198
1 discount = 178 yen
3 discount = 138 yen
5 discount = 99 yen
8 discount = 39 yen

*I'm assuming here that one discount is 0.9x, but if you want to make it clear that it's one discount, you can use
(int)(price * (1 - 0.1)) to make it more like 1 discount.
*A variable can be created and assigned for each discount.
*The result may be a real number.
*The results may differ slightly depending on the calculation method, but if the calculation method is correct, it is considered correct.
Note that it is easy to forget the & that is attached to a variable in the scanf function.
Short Answer Type (Sample Answer)

Solution 4-1
The scanf function is not capable of checking for input errors.

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


Open the 💬 comment submission box