Lesson 10: C Programming - How to test to see if a number is ODD or EVEN using Modulus Operator.

preview_player
Показать описание
#shorts, #softwarenuggets , @SoftwareNuggets ,#softwareShorts

Welcome to this C programming tutorial where we will learn how to determine whether a number is even or odd using the modulo operator and an if-else statement.

This code may look a bit complex at first, but it's actually quite simple. Let me break it down for you.

The first line #include stdio.h tells the compiler to include the standard input/output library. This library provides the printf() function, which we will use to print whether the number is even or odd.

The second line void main() declares the main function, which is the entry point of any C program.

Inside the main function, we declare a variable n and initialize it to 5.

We then use an if-else statement to determine whether n is even or odd. The modulo operator % gives us the remainder when n is divided by 2. If the remainder is 0, then n is even. Otherwise, n is odd.

If n is even, we print the message "%d is even", where %d is replaced with the value of n. If n is odd, we print the message "%d is odd", where %d is replaced with the value of n.
Рекомендации по теме