myusufs

prime

Feb 25th, 2021
601
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,y;
  5.     printf("Menentukan Bilangan Genap, Ganjil, dan Prima\n\n");
  6.     printf("Masukan Rentang Bilangan\n");
  7.     printf("Masukkan bilangan bulat pertama  : "); scanf("%d",&x);
  8.     printf("Masukkan bilangan bulat terakhir : "); scanf("%d",&y);
  9.    
  10.     printf("\nBilangan yang ditemukan : \n");
  11.     for(i=x;i<=y;i++){
  12.         if(i%2==0)
  13.             printf("%d Bilangan Genap\n",i);
  14.         else{
  15.             prima=cekprima(i);
  16.             if(prima==1)
  17.                 printf("%d Bilangan Ganjil dan Bilangan Prima\n",i);
  18.             else
  19.                 printf("%d Bilangan Ganjil\n",i);
  20.         }
  21.     }
  22.     getch();
  23. }
  24.  
  25. int cekprima(bil){
  26.     int bagi=3;
  27.     int batas;
  28.     if(bil==1)
  29.         return(0);
  30.     else if(bil==2||bil==3)
  31.         return(1);
  32.     else{
  33.         while(batas>bagi){
  34.             if(bil%bagi==0){
  35.                 return(0);
  36.                 break;
  37.             }
  38.             batas=bil/bagi;
  39.             bagi+=2;
  40.         }
  41.         return(1);
  42.     }
  43. }
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.

×