Cara Mengecek & Memeriksa Nomor Genap dan Ganjil di Pemrograman C++

Cara Mengecek & Memeriksa Nomor Genap dan Ganjil di Pemrograman C++

Pada kesempatan ini TeknoTips.NET akan mengulas tentang "" dengan judul artikel "Cara Mengecek & Memeriksa Nomor Genap dan Ganjil di Pemrograman C++".

To understand this example, you should have knowledge of following C++ programming topics:
Integers which are perfectly divisible by 2 are called even numbers. And those integers which are not perfectly divisible by 2 are not known as odd number. To check whether an integer is even or odd, the remainder is calculated when it is divided by 2 using modulus operator %. If remainder is zero, that integer is even if not that integer is odd.
C++ Program to Check Whether Number is Even or Odd

Output
Enter an integer: 23
23 is odd.
In this program, if..else statement is used to check whether n%2 == 0 is true or not. If this expression is true, n is even if not n is odd.
You can also use ternary operators ?: instead of if..else statement. Ternary operator is short hand notation of if...else statement.

#include <iostream>
using namespace std;
int main() {
    int n;
    cout << "Enter an integer: ";
    cin >> n;
    
    (n%2 == 0) ? cout << n << " is even." :  cout << n << " is odd.";
    
    return 0;
}
 

Check out these related examples :


Kata Kunci : C Plus Plus English, Cpp Examples,
Untuk mendapat notifikasi setiap artikel terbaru, masukkan e-mail anda disini : Tuliskan komentar relevan anda dibawah ini dengan jelas & sopan, sesuai dengan topik ulasan mengenai C Plus Plus English Terbaru 2019.

Untuk menghindari spam dan tautan aktif, komentar akan dimoderasi. Dapatkan balasan dari melalui e-mail anda :

Komentar artikel "Cara Mengecek & Memeriksa Nomor Genap dan Ganjil di Pemrograman C++"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel