Made Program Prime Number Checker Using C++

Prime number is unique number because this number can only divided by 1 (one) and this number too. But, in the real life frequently, we get confused whether determine that the number is prime or not. with this code, hopely can help you to solved that case. thanks

ant this the script :

/*==========================
Program : Prime Number Checker
Date  : August 25 2016
Created by Ss97
========================*/
#include <iostream>

using namespace std;

int cekPrima (int angka){
   int pembagi=0;
   int prim;
   for(int i=1;i<=angka;i++){
      if(angka%i==0){
          pembagi++;
      }
   }
   if(pembagi==2){
      prim=1;
   }
   else{
      prim=0;
   }
   return(prim);
}

void input (int& angka){
   cout<<"Masukan Angka yang mau diCheck = ";cin>>angka;
}

void cetak (int angka){
   if(cekPrima(angka)){
      cout<<angka<<" Merupakan Bilangan Prima"<<endl;
   }
   else{
     
      cout<<angka<<" Bukan Bilangan Prima"<<endl;
   }
}
void menu (){
   int pilih=1,angka;
   while(pilih==1){
      system("CLS");
      cout<<"SELAMAT DATANG DI PROGRAM PENGECHECK BILANGAN PRIMA"<<endl;
      input(angka);
      cetak(angka);
      cout<<"Pilih 1 Untuk Mengecheck Angka yang lain ";cin>>pilih;
   }
}
main (){
   menu();
}

after compiled and run it :

Thanks for the attention, Hopefuly it can help you :D

Tidak ada komentar

Diberdayakan oleh Blogger.