Home>

Please write your question in detail here.
I don't see the error in this code.
How many times are the 4th, 6th, and 8th lines executed?
■■ The following error message occurred while implementing the function.

include

void func (int n) {
if (n<= 2) {
printf ("4th line% d", n);
} else {
printf ("6th line% d", n);
func (n-3);
printf ("8th line% d", n);
}
}
void main () {
func (12);
}

Error message
do not know

Language name here
C
`` ```

What I tried Supplementary information (FW/tool version, etc.)

Please provide more detailed information here.

c
  • Answer # 1

    When printing with printf, make sure to print the line feed code as shown below.
    Then, I wonder if I can get the desired result.

    #include<stdio.h>
    #include<string.h>
    void func (int n) {
    if (n<= 2) {
    printf ("4th line% d \ n", n);
    } else {
    printf ("6th line% d \ n", n);
    func (n-3);
    printf ("8th line% d \ n", n);
    }
    }
    void main () {
    func (12);
    }


    Execution result
    6th line 12
    6th line 9
    6th line 6
    6th line 3
    4th line 0
    8th line 3
    8th line 6
    8th line 9
    8th line 12

  • Answer # 2

    I don't see the error in this code.

    No particular error occurs (paiza.io). In addition, it should be notedmainOnly in front ofintIs being rewritten to.