Cara C++ Mengolah Bilangan Prima

2

29 Oktober 2012 oleh Rizky Zakaria

Kalau belum punya software editing program C++ bisa cek disini: http://www.bloodshed.net/devcpp.html

Dan dibawah ini listing program Bilangan Prima:

#include<stdio.h>

#include<conio.h>

void prima (),bsort();

main()

{

start:

int x;

printf (“\n \t Algoritma Brute Force \n”);

printf (“\n=======================”);

printf (“\n \t 1. Pencarian Bilangan Prima”);

printf (“\n \t 2. Sorting Bilangan”);

printf (“\n \t 3. Exit”);

printf (“\n=======================\n”);

printf (“\n Masukkan Pilihan (1-3) : “);

scanf      (“%d”,&x);

switch (x)

{

case 1 : prima ();

goto start;

case 2 : bsort ();

goto start;

case 3 : return 0;

printf (“\n \n \n \n \n \n \t \t \t Anda Salah Memasukan Input”);

printf (“\n \t \t Program Akan Direstart Setelah Anda Menekan Tombol Enter”);

getch();

goto start;

}

}

void prima ()

{

int bil,j;

printf (“\t \t \t Pencarian Bilangan Prima \n \n \n”);

printf (“Masukkan Data Yang ingin Diinput: “);

scanf (“%d”,&bil);

for (j=2;j<=bil;j++)

{

if ((j%2>0) && (j%3>0)&&(j%5>0)&&(j%7>0) ||

(j==2)|| (j==3)||(j==5)||(j==7))

printf (“%i”,j);

}

getch();

}

void bsort()

{

int i,j,temp,n,bil[100];

printf (“\t \t \t Sorting BIlangan \n \n \n”);

printf (“Masukkan Jumlah bilangan: “);

scanf(“%d”,&n);

for (i=0;i

{

printf (“Bilangan ke-%d \t: “,i+1);

scanf (“%d”,&bil[i]);

}

printf (“\n”);

for (i=0;i

{

for (j=n-1;j>i;j–)

{

if(bil[i] > bil[j]){

temp = bil[i];

bil[i] = bil[j];

bil[j] = temp;

}}}

printf (“Sorting:”);

for(i=0;i<n;i++)

{

printf (“%d”,bil[i]);

if (i!=n-1)

{

printf (“,”);

}}

getch();}

 

Bagi yang belum tau gimana cara menggunakan dev c++, ane kasih tau nih:

Pertama : anda download dahulu software dev c++, lalu install dah.

Kedua : anda bisa memulai memasukkan listing program diatas dengan terlebih dahulu membuat program baru dengan langah-langah: FILE > NEW > SOURCE FILE.

Ketiga: copy listing program diatas lalu paste dibagian blok putih seperti gambar dibawah ini:

 

Setelah anda mengcopy listing, terlebih dahulu lakukan save program yang anda buat, lalu COMPILE & RUN (F9).

Maka akan muncul program Bilangan Prima seperti ini:

 

 

 

Untuk keluar dari program diatas ketik saja 3 pas anda kembali ke menu pilihan.

2 thoughts on “Cara C++ Mengolah Bilangan Prima

  1. Richard mengatakan:

    Gan, pas disalin ulang ke dev c++, ada yang error gan.. dan saya masih kurang jelas yang for(i=0;i ? apa bisa ditulis dengan format sepertin itu? biasa saya belajar for(i=0;i<=n;i++)
    mohon penjelasannya gan.

    • Rizky Zakaria mengatakan:

      Oh iya maaf gan.. Ane lupa nambahin kodingan.. Emang bener yang agan kasih.. Emang kayak gitu.. Tapi kalo coba di turbo borland c sama di dev c++ ane pernah coba, tingkat sensitifnye buat koding banyak kesalahan di borland. thanks gan atas koreksinye, hehe ane pas mosting emang lagi coba-coba juga.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

Masukkan alamat surat elektronik Anda untuk mengikuti blog ini dan menerima pemberitahuan tentang tulisan baru melalui surat elektronik.

Bergabunglah dengan 1 pengikut lainnya

My Profile

Tanggal/Bulan/Tahun

Oktober 2012
S S R K J S M
« Sep   Des »
1234567
891011121314
15161718192021
22232425262728
293031  

7zip (Alternatif Selain WinRAR)

RSS detiksepakbola

RSS File Hippo

  • Spotify 1.0.44.100 9 Desember 2016
    With Spotify, it’s easy to find the right music for every moment – on your phone, your computer, your tablet and more. There are millions of tracks on Spotify. So whether you’re working out, partying or relaxing, the right music is always at your fi...
  • StressMyPC 2.91 9 Desember 2016
    If you need to test your computer's performance to ensure it is running at optimal capacity, then it is a good idea to run a stress test and analyze the results. StressMyPC is a small, lightweight and useful tool for the job. It actually does not req...
  • Calibre 2.74.0 64-bit 9 Desember 2016
    Calibre is a complete e-book library manager that lets you totally organize your collection. With Calibre you can convert your books to multiple formats, and then sync with all of your devices. KEY FEATURES INCLUDE: Library management. Calibre ...
  • Calibre 2.74.0 32-bit 9 Desember 2016
    Calibre is a complete e-book library manager that lets you totally organize your collection. With Calibre you can convert your books to multiple formats, and then sync with all of your devices. KEY FEATURES INCLUDE: Library management. Calibre...
  • LastPass: Free Password Manager 4.1.34 9 Desember 2016
    LastPass is an award-winning password manager that can save your passwords and provide you with secure access from every computer and mobile device you have. With LastPass you need only remember one password - your LastPass master password. With t...

RSS detikInet

  • Sebuah galat telah terjadi; umpan tersebut kemungkinan sedang anjlok. Coba lagi nanti.

RSS detikOto

  • Sebuah galat telah terjadi; umpan tersebut kemungkinan sedang anjlok. Coba lagi nanti.
%d blogger menyukai ini: