Practice Problem 9
Basics
Question 1-1
What is the colloquial name for the variable used to count repetitions in a for loop?
Question 1-2
What do we colloquially call a `for` loop that runs forever?
Program reading
What program is intended to display what?
Determine the answer based on the processing content and variable names.
Determine the answer based on the processing content and variable names.
Question 2-1
#include <stdio.h>
int main(void)
{
int i, price;
scanf("%d", &price);
for (i = 1; i <= 9; i++) {
printf("%d Price Down = %d\n", i, (int)(price * ((10.0 - i) / 10)));
}
return 0;
}
Program Manual
Question 3-1
Write a program that uses a for loop to display a multiplication table.
Hint: Use the %2d specifier to align tables.
Hint: You can use a for loop inside another for loop.
Hint: Use the %2d specifier to align tables.
Hint: You can use a for loop inside another for loop.
explanatory
Question 4-1
Briefly explain how a for loop with a constant number of iterations works.
Fundamentals (Answer Key)
Solution 1-1
Count variable or loop variable
Solution 1-2
Infinite loop
Program Reading (Solution Example)
Solution 2-1
A program that displays prices with discounts ranging from 1% to 9% when a fixed price is entered.
The discount rate is calculated by dividing 10.0 by i, and then dividing the result by 10.
Program Documentation (Example Solution)
Question 2-1
#include <stdio.h>
int main(void)
{
int x, y;
for (x = 1; x <= 9; x++) {
for (y = 1; y <= 9; y++) {
printf(" %2d ", x * y);
}
printf(" \n");
}
return 0;
}
printf(\n);
You can use `for` loops as well as other blocks (compound statements) in any level of nesting.
However, please pay attention to code readability.
Descriptive (answer example)
Solution 4-1
Initially set the variable to 1, increment it by 1 each time, and terminate the loop when the variable's value exceeds the specified number of iterations. This achieves a loop with a fixed number of iterations.
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.




