C language learned by suffering
C language learned by suffering
Exercise 10
fundamental knowledge
Q1-1
What do you call a repetition in which the condition is determined first, like a while statement?
Q 1-2
What do you call a repetition in which the condition is judged afterwards, such as a do to while statement?
program read-only
What is the next program to display?
Answer by judging from the process contents and variable names.
Answer by judging from the process contents and variable names.
Q2-1
#include <stdio.h>
int main(void)
{
int year = 0;
double money = 10000;
while (money < 15000) {
year++;
money *= 1.01;
}
printf("%d , %f\n", year, money);
return 0;
}
program writing
Q3-1
I want to create a program to input test scores.
However, since test scores only range from 0 to 100
If any other value is entered, it should be re-entered.
However, since test scores only range from 0 to 100
If any other value is entered, it should be re-entered.
descriptive expression
Q4-1
Briefly explain why do~while statements are good for input checking.
Basic Knowledge (sample answers)
Solution 1-1
preliminary determination
Solution 1-2
LIFO
Program reading (example solution)
Solution 2-1
If you deposit 10,000 yen in a bank with an interest rate of 1% per annum
The program displays how many years it will take to reach 15,000 yen.
The program displays how many years it will take to reach 15,000 yen.
Program writing (example of solution)
Solution 3-1
#include <stdio.h>
int main(void)
{
int score;
do {
printf("Please enter score:");
scanf("%d", &score);
} while (score < 0 || score > 100);
printf("Score entered %d\n", score);
return 0;
}
If you want to display a message upon re-entry, do the following
The variable score is distinguished whether it is the first input or not by whether it contains 0 or not.
If 0 is entered in score, the loop exits, so the conditions do not overlap.
Solution 3-1 Solution 2
#include <stdio.h>
int main(void)
{
int score;
do {
printf("Please enter score:");
scanf("%d", &score);
} while (score < 0 || score > 100);
printf("Score entered %d\n", score);
return 0;
}
problem
Short Answer Type (Sample Answers)
Solution 4-1
Since the do~while statement is a post-determination loop, it is always executed once at the beginning and
The reason for this is that there is no situation where no input is made.
The reason for this is that there is no situation where no input is made.
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.