Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of if in C language programming

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

  • How to use WeChat Mini Programs selector

    This article mainly introduces the relevant knowledge of "how to use WeChat Mini Programs selector". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use WeChat Mini Programs selector" can help you solve the problem. Page structure

    © 2024 shulou.com SLNews company. All rights reserved.

    12
    Report