Last active
September 12, 2023 00:01
-
-
Save Khuirul-Huda/14bcf45448ec075fc17f06e8ee1453c2 to your computer and use it in GitHub Desktop.
punya huda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
// fungsi untuk menentukan apakah input bilangan prima atau tidak... fungsi ini mereturn boolean benar atau salah | |
bool isPrima(int number) { | |
int prima = true; | |
// karena bilangan prima adalah bilangan yang habis dibagi 1 dan bilangan itu sendiri maka dibuat perulangan untuk mengecek tiap angka apakah bisa habis membagi bilangan yang diberikan | |
if (number <= 0 || number == 1) { | |
return false; | |
} | |
for (int i = 2; i < number ; i++) { | |
if ((number % i) == 0) { | |
prima = false; //bilangan bukan prima | |
} | |
} | |
return prima; | |
} | |
int main() { | |
// print nama/identitas | |
cout << "Nama: Muhammad Khuirul Huda" << endl; | |
cout << "NIM: 2300000" << endl; | |
cout << "Kelompok: 15. Clion" << endl; | |
cout << "Prodi: Teknik Informatika" << endl; | |
// meminta input dari user | |
int input; | |
cout << "Masukkan angka:"; | |
cin >> input; | |
if (isPrima(input)) { | |
cout << "Angka " << input << " adalah bilangan prima" << endl; | |
} else { | |
cout << "Angka " << input << " bukan bilangan prima" << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment