myusufs

bil_prima

Feb 25th, 2021
609
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <conio.h>
  3. int main(){
  4.     int i,prima,x=2741,y=2800;
  5.     printf("Mencari Bilangan Genap atau Ganjil\n");
  6.     printf("\nBilangan yang ditemukan : \n");
  7.     for(i=x;i<=y;i++){
  8.         if(i%2==0)
  9.             printf("%d Bilangan Genap\n",i);
  10.         else{
  11.             prima=cekprima(i);
  12.             if(prima==1)
  13.                 printf("%d Bilangan Ganjil dan Bilangan Prima\n",i);
  14.             else
  15.                 printf("%d Bilangan Ganjil\n",i);
  16.         }
  17.     }
  18.     getch();
  19. }
  20.  
  21. int cekprima(bil){
  22.     int bagi=3;
  23.     int batas;
  24.     if(bil==1)
  25.         return(0);
  26.     else if(bil==2||bil==3)
  27.         return(1);
  28.     else{
  29.         while(batas>bagi){
  30.             if(bil%bagi==0){
  31.                 return(0);
  32.                 break;
  33.             }
  34.             batas=bil/bagi;
  35.             bagi+=2;
  36.         }
  37.         return(1);
  38.     }
  39. }
  40.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×