learn through suffering C language learn through suffering 
C language

Practice Problem 4

Basics


Question 1-1
What is the term for a string enclosed in "" ?


Question 1-2
In mathematics, what symbol is used instead of the × symbol when writing in C?


Question 1-3
What symbol is used in C language instead of the division symbol ÷ in mathematics?


Question 1-4
What notation is used in C to represent floating-point numbers?

Program reading

How will the program be displayed when executed?

Question 2-1
#include <stdio.h>

int main(void)
{
    printf("%d\n", 20 / 7);
    printf("%f\n", 20.0 / 7.0);
    return 0;
}

Program Manual


Question 3-1
Create a program that calculates 40 ÷ 13 and displays the expression, quotient, and remainder.

explanatory


Question 4-1
In C, when performing integer division,
if the result cannot be divided evenly, it is truncated.
Explain concisely why this occurs.

Fundamentals (Answer Key)


Solution 1-1
String literal


Solution 1-2
*

※ Read as asterisk.

Solution 1-3
/

(※ Read as a slash.)

Solution 1-4
Floating-point

Program Reading (Solution Example)


Solution 2-1
2
2.857143

Please note that integer division truncates, rather than rounds.
For real number answers, accuracy to two decimal places is sufficient.
Question

Program Documentation (Example Solution)


Solution 3-1
#include <stdio.h>

int main(void)
{
    printf("%d / %d = %d ... %d\n", 40, 13, 40 / 13, 40 % 13);
    return 0;
}

Note that different symbols for division or remainder are also considered correct.
While displaying the expression as a string is also considered correct, using a format specifier (%d) is preferable.
Do not perform calculations; answers provided as strings will be marked incorrect.

Descriptive (answer example)


Solution 4-1
When rounding, performing the inverse calculation of quotient × divisor results in a value greater than the original dividend, creating a contradiction. Therefore, rounding down reduces contradictions and minimizes calculation errors.



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. line break
  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

Loading comment system...