Practice Problem 6
Basics
Question 1-1
What function is used to input numbers from the keyboard?
Question 1-2
What symbol do you put before variable names when using the functions mentioned above?
Program reading
What is the purpose of this program, i.e., what does it calculate?
Determine the answer based on the content and variable names.
Determine the answer based on the content and variable names.
Question 2-1
#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 documentation
Question 3-1
When you enter the original price, it will calculate the prices with 10%, 30%, 50%, and 80% discounts.Create a program to list items.While it's preferable to display the result as a whole number, a decimal value is also acceptable.
explanatory
Question 4-1
In reality, the scanf function is rarely used in programs where reliability is required.
Explain it briefly, why?
Explain it briefly, why?
Fundamentals (Answer Key)
Solution 1-1
scanf function
While I haven't introduced them yet, there are many other similar functions available.
Solution 1-2
&
Program Reading (Solution Example)
Solution 2-1
The program calculates the area of a triangle, as indicated by the variable names (side, height, area) and the processing logic (side × height ÷ 2).
If you can somehow figure it out, even without a detailed explanation, that's considered correct.
It might have been a rather difficult problem.
However, to continue developing programs, it is essential to read programs written by others.
Let's strive to understand not just the program's processing, but also its purpose!
Program Documentation (Example Solution)
Question 3-1
#include <stdio.h>
int main(void)
{
int price;
printf("Please enter the list price. : ");
scanf("%d", &price);
printf("1discount = %dCircle\n", (int)(price * 0.9));
printf("3discount = %dCircle\n", (int)(price * 0.7));
printf("5discount = %dCircle\n", (int)(price * 0.5));
printf("8discount = %dCircle\n", (int)(price * 0.2));
return 0;
}
Results
Please enter the list price: 198 yen
10% off = 178 yen
30% off = 138 yen
50% off = 99 yen
80% off = 39 yen
10% off = 178 yen
30% off = 138 yen
50% off = 99 yen
80% off = 39 yen
※ Here, we are representing a 10% discount as 0.9, but if you want to explicitly state it as a 10% discount,
(int)(price * (1 - 0.1)) will likely apply a 10% discount.
You can create variables for each discount and assign values to them.
The result may be a real number.
Depending on the calculation method, the results may vary slightly, but if the method is correct, the answer is considered correct.
Be careful not to forget the & when assigning variables with the scanf function.
descriptive (answer)
Solution 4-1
The `scanf` function cannot check for input errors.
About This Site
Learning C language through suffering (Kushi C) isThis is the definitive introduction to the C language.
It systematically explains the basic functions of the C language.
The quality is equal to or higher than commercially available books.




