Practice Problem 11
Basics
Question 1-1
What is it called when you declare the form of a function at the beginning of a program?
Question 1-2
What do you call the variables declared to pass numbers to a function?
Question 1-3
What do we call the numbers or variables passed to a function?
Question 1-4
What do we call the value returned from a function?
Program reading
What is the purpose of the function tri in the following program?
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 tri(int, int);
int main(void)
{
int side, high, square;
scanf("%d,%d", &side, &high);
printf("%d\n", tri(side, high));
return 0;
}
int tri(int side, int high)
{
return side * high / 2;
}
Program documentation
Question 3-1
Write a program that takes a year as input and displays whether or not the Olympics were held in that year.
However, please create the section that calculates the Olympic Games as a separate function.
The first tournament was held in the summer of 2000, and subsequent tournaments are scheduled to be held every two years, alternating between winter and summer.
And let's make sure this schedule stays locked in.
However, please create the section that calculates the Olympic Games as a separate function.
The first tournament was held in the summer of 2000, and subsequent tournaments are scheduled to be held every two years, alternating between winter and summer.
And let's make sure this schedule stays locked in.
explanatory
Question 4-1
Briefly explain the purpose of creating functions.
Fundamentals (Answer Key)
Solution 1-1
Prototype Declaration
Solution 1-2
default argument
Solution 1-3
actual arguments
Solution 1-4
return value
Program Reading (Solution Example)
Solution 2-1
A function to calculate the area of a triangle.
Program Documentation (Example Solution)
Solution 3-1
#include <stdio.h>
int olympic(int year);
int main(void)
{
int year, hold;
scanf("%d", &year);
hold = olympic(year);
switch (hold) {
case 0:
printf("Unopened\n");
break;
case 1:
printf("Summer Olympics\n");
break;
case 2:
printf("Winter Olympics\n");
break;
};
return 0;
}
int olympic(int year)
{
if (year % 2 == 0) {
if (year % 4 == 0) {
return 1;
} else {
return 2;
}
} else {
return 0;
}
}
The return value of the Olympic function is linked to the event.
Please be mindful of declaring prototypes.
descriptive (answer)
Solution 4-1
By creating functions for specific tasks and combining them, the entire program is completed, making it easier to build even large programs.
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.




