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

Practice Problem 13

Fundamentals

Question 1-1
What is the term for handling variables of the same type collectively?

Program reading
What is this program calculating?
Determine the answer based on the processing content and variable names.

Question 2-1
#include <stdio.h>

int main(void)
{
    int data[] = { 79, 42, 39, 79, 13, 75, 19 };
    int i, sum = 0, avg;

    for (i = 0; i < sizeof(data) / sizeof(data[0]); i++) {
        sum += data[i];
    }

    avg = sum / (sizeof(data) / sizeof(data[0]));

    printf("%d\n", avg);

    return 0;
}

Program Manual

Question 3-1
Create a program that displays the 10 input numbers from last to first.

descriptive

Question 4-1
Briefly explain what the main advantage of arrays is.

Fundamentals (Answer Key)

Solution 1-1
array

Program Reading (Solution Example)

Solution 2-1
Calculating the average.

Program Documentation (Example Solution)

Solution 3-1
#include <stdio.h>

int main(void)
{
    int data[10];
    int i;

    for (i = 0; i < 10; i++) {
        printf("%d 番目のnumericsを入力して下さい:", i);
        scanf("%d", &data[i]);
    }

    for (i = 9; i >= 0; i--) {
        printf("%d ", data[i]);
    }

    printf("\n");

    return 0;
}

Note that the loop is being iterated in reverse order here.
You can also write it to reverse only the specified numbers, as follows.

Alternative phrasing
for (i = 0; i < 10; i++) {
    printf("%d ", data[9 - i]);
}

descriptive (answer)

Solution 4-1
By specifying numbers with variables, it's possible to handle a large number of variables collectively.



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