Practice Problem 15
Basics
Question 1-1
What is the term for the memory address assigned to a variable?
Question 1-2
What is the term for the method of assigning the above numbers to variables and handling them?
Program reading
In the following program, the return value of the sum function is of type void, yet...
Please briefly explain why calculations can be returned.
Please briefly explain why calculations can be returned.
Question 2-1
#include <stdio.h>
void sum(int, int, int *);
int main(void)
{
int value;
sum(50, 100, &value);
printf("%d\n", value);
return 0;
}
void sum(int min, int max, int *ans)
{
*ans = (min + max) * (max - min + 1) / 2;
return;
}
Program Manual
Question 3-1
Create a program that finds and displays the maximum and minimum values from multiple numbers entered within the range 0 to 100.
If -1 is entered, treat it as the end of input.
However, the maximum and minimum values must be calculated within a single function outside the main function.
Also, set the array size to store the entered numbers to 10 elements.
If more than 10 numbers are entered, it is acceptable for an error to occur.
Hint: If -1 is present in the array, it can be determined that data input has ended.
Hint: To find the minimum value, repeatedly compare each number with the variable storing the maximum value.
If -1 is entered, treat it as the end of input.
However, the maximum and minimum values must be calculated within a single function outside the main function.
Also, set the array size to store the entered numbers to 10 elements.
If more than 10 numbers are entered, it is acceptable for an error to occur.
Hint: If -1 is present in the array, it can be determined that data input has ended.
Hint: To find the minimum value, repeatedly compare each number with the variable storing the maximum value.
explanatory
Question 4-1
In short, what is a pointer?
Fundamentals (Answer Key)
Solution 1-1
address
Solution 1-2
Pointer
Program Reading (Solution Example)
Solution 2-1
The third argument of the sum function is declared as a pointer-type variable,
and passing an address to it allows the contents of the variable to be directly overwritten.
and passing an address to it allows the contents of the variable to be directly overwritten.
Program Documentation (Example Solution)
Solution 3-1
#include <stdio.h>
void maxmin(int array[], int *max, int *min);
int main(void)
{
int i = 0, array[10], max, min;
do
{
printf("%dth number:", i + 1);
scanf("%d", &array[i]);
i++;
} while (array[i - 1] != -1);
maxmin(array, &max, &min);
printf("maximum value %d : minimum value %d\n", max, min);
return 0;
}
void maxmin(int array[], int *max, int *min)
{
int i = 0;
*max = 0;
*min = 100;
while (array[i] != -1)
{
if (array[i] > *max) *max = array[i];
if (array[i] < *min) *min = array[i];
i++;
}
}
That might have been a bit challenging.
But if I could write programs this smoothly,
I'm at a level that just barely cuts it as a professional programmer.
Keep practicing and try again!
Descriptive (answer example)
Solution 4-1
A shortcut variable for a variable.
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.




