Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of if in C language programming

Shulou Source: shulou.com Published: 2022-06-02 22:45:01 09月24日 Update

C language programming in what is the use of if, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Sequence, selection and loop are the three basic structures of a program, and no matter how complex the program is, it is written with these three structures.

Usage of if (example 1)

# include

Int main (void)

{

If (true)

If (false)

Printf ("!\ n")

Else

Printf ("hehe!\ n"); / / pay attention to the correspondence between else and if, and the correspondence between else and if is from the middle to the opposite end.

If (true)

{

If (false)

Printf ("!\ n")

}

Else

Printf ("hehe!\ n"); / / for else to correspond to the first if, you must enlarge parentheses on the if statement that should correspond to it to make it a separate sentence.

Return 0

}

Program output:

Example 2

# include

Int main (void)

{

If (3) / / if (): deal with true or false, 0 is false, non-0 is true

{

Printf ("AAAA\ n")

Printf ("BBBB\ n")

}

Return 0

}

Program output:

Example 3

# include

Int main (void)

{

/ / int i, j

/ / printf ("Please enter the value of I j:")

/ / scanf ("d d", & I, & j)

If (2 times 3)

Printf ("I is greater than j\ n")

Else

Printf ("I is less than j\ n")

Return 0

}

Program output:

Example 4:

# include

Int main (void)

{

Int x

Int y

Printf ("Please enter a value for x:")

Scanf (& d, & x)

Y = 0

If (x > = 0)

If (x > 0)

Y = 1

Printf ("y =% d\ n", y)

Return 0

}

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Programs examples output structure help input language programming programming complexity clarity three big two ends content for this parentheses articles novices more true or false Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Huawei Redmi macOS NVidia