MMGames Introduction to C C Language Development Environment C language now Useful Apps Contact Us
MMGames

Automatic version identification

SpineViewer

It's easy to tell by looking at it.

Response Time Checker

I can leave my computer on and do it.

Mouse cleaning time

I can leave my computer on and do it.

Mouse cleaning time

C language learned by suffering
C language learned by suffering

Exercise 15

fundamental knowledge

Q1-1
What do you call the number in memory attached to a variable?


Q 1-2
What do you call the method of handling the above number by assigning it to a variable?

program read-only
In the following program, even though the return value of the sum function is of type void
Briefly explain why it is possible to return the result of a calculation.

Q2-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 writing

Q3-1
From multiple numbers entered in the range of 0-100.
Create a program to find and display the maximum and minimum values.

If -1 is entered, it is judged to be the end of the input.
However, the maximum and minimum values are obtained in one function other than the main function.
The number of elements of the array that stores the input numerical values shall be 10, and the number of elements of the array that stores the input numerical values shall be 10.
If more than that is entered, it is assumed that an error is unavoidable.

Hint: A -1 in the array indicates the end of the data.
Tip: To find the minimum value, repeat the comparison with the variable that stores the maximum value.

descriptive expression

Q4-1
After all, briefly explain what a pointer is.

Basic Knowledge (sample answers)

Solution 1-1
address


Solution 1-2
pointer

Program reading (example solution)

Solution 2-1
The third argument of the sum function is declared as a variable of type pointer.
Because the contents of the variable can be directly rewritten by passing the address to it.

Program writing (example of 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("max %d : min %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++;
    }
}

*Maybe it was a little too challenging.
 But if you can write a program as smooth as this one
 This level is just barely acceptable for a professional programmer.
 After further study, you can try again!
Short Answer Type (Sample Answers)

Solution 4-1
A shortcut variable for a variable.



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.

Part 0: Program Overview
  1. What is the program?
Chapter 2: How to write a program
  1. Writing Rules
  2. Writing conventions
  3. Exercise 2
Chapter 3: Display on Screen
  1. String display
  2. newline character
  3. Exercise 3
Chapter 4: Numeric Display and Calculation
  1. Numeric Display
  2. Basic Calculations
  3. Type of value
  4. Exercise 4
Chapter 5: Numerical Memory and Calculation
  1. Memorize values
  2. Variable Type
  3. Type conversion
  4. Numeric justification
  5. Exercise 5
Chapter 6: Input from the keyboard
  1. Functions for input
  2. Fear of Input
  3. Exercise 6
Chapter 9: Repetition with a fixed number of times
  1. Sentences that repeat themselves
  2. Loop Operation Mechanism
  3. Exercise 9
Chapter 10: Unknown number of repetitions
  1. Loop of unknown frequency
  2. input check
  3. Exercise 10
Chapter 13: Handling Multiple Variables at Once
  1. Multiple variables are handled together.
  2. How to use arrays
  3. Exercise 13
Chapter 19: Dynamic Arrays
  1. Create arrays at will
  2. Exercise 19
Chapter 20: Multiple Source Files
  1. Minimal division
  2. The Stone of Division
  3. Exercise 20

Comment
COMMENT

Open the 💬 comment submission box