MMGameslogo  MMGames
TwitterSharebutton  FacebookSharebutton   
learn through sufferingC Language
learn through sufferingC Language

Practice Problem 11

Fundamentals

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 processing 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 Manual

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, the section calculating the Olympic Games should be created 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.

descriptive

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("開かれない\n");
        break;
    case 1:
        printf("夏季五輪\n");
        break;
    case 2:
        printf("冬季五輪\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
機能別にfunctionを作り、それを組み合わせることでプログラム全体が完成し、
to make it easier to build even large programs.



About This Site

Learning C language through suffering (Kushi C) is
This 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.

Part 0: Program Overview
  1. What is a program?
Chapter 3: Displaying on the Screen
  1. String Display
  2. newline character
  3. Practice Problem 3
Chapter 4: Displaying and Calculating Numbers
  1. Display of numbers
  2. Basic calculations
  3. Numeric types
  4. Practice Problem 4
Chapter 6: Input from the Keyboard
  1. input function
  2. The fear of input
  3. Practice Problem 6
Chapter 9: Repeating a Fixed Number of Times
  1. Iterative sentence
  2. How Loops Work
  3. Practice Problem 9
Chapter 10: Repeating Without Knowing the Number of Times
  1. Unspecified loop
  2. Input validation
  3. Practice Problem 10
Chapter 13: Handling Multiple Variables at Once
  1. Handling multiple variables collectively.
  2. Arrays
  3. Practice Problem 13
Chapter 19: Dynamic Arrays
  1. Create arrays freely.
  2. Practice Problem 19