How to determine odd and even numbers in C language

藏色散人
Release: 2020-03-03 11:13:33
Original
87987 people have browsed it

How to determine odd and even numbers in C language

How to determine odd and even numbers in C language?

Step one: First open our DEV C software, and then click "New Source Code".

Recommended: "C Language Tutorial"

How to determine odd and even numbers in C language

Step 2: Enter the following code on our editing page:

#include<stdio.h> 
 int main() 
 {
      int a;
      printf("请输入一个整数:");
     scanf("%d",&a);
    if(a%2==0)
    printf("%d为偶数!",a);
    else
    printf("%d为奇数!");
    return 0;
 }
Copy after login

How to determine odd and even numbers in C language

Step 3: Because the question requires us to input an integer first, when we define the variable, we should define it as an integer type. Note that in the input and output functions , our integer type corresponds to "%d".

How to determine odd and even numbers in C language

Step 4: Next we have to judge the integer we input. In C language, if is a judgment statement, so we use it to judge our integers. if (a%2==0) is a judgment code recognized by our computer.

How to determine odd and even numbers in C language

Step 5: Because we need to output the results, not just judge, so we need to combine else to judge and output the results. See the picture below for the specific code

How to determine odd and even numbers in C language

Finally, click "Run". After the input page pops up, enter an integer and click Enter to get the result we want. The desired result.

How to determine odd and even numbers in C language

For more programming-related content, please pay attention to the Programming Introduction column on the php Chinese website!

The above is the detailed content of How to determine odd and even numbers in C language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!