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 berkata:

    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 berkata:

      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

  • Bandicam 3.4.0.1227 27 April 2017
    With Bandicam screen recorder you can video record a certain area on a PC screen, or you can record a program which uses the DirectX/OpenGL graphic technologies. Bandicam screen recorder works with a high compression ratio, whilst keeping the video...
  • LibreOffice 5.3.3 RC 1 27 April 2017
    LibreOffice is the free power-packed Open Source personal productivity suite for Windows, Macintosh and Linux, that gives you six feature-rich applications for all your document production and data processing needs. Writer is the word processor insi...
  • LibreOffice 5.3.3 RC 1 64-bit 27 April 2017
    LibreOffice is the free power-packed Open Source personal productivity suite for Windows, Macintosh and Linux, that gives you six feature-rich applications for all your document production and data processing needs. Writer is the word proc...
  • Dropbox 24.4.17 27 April 2017
    Dropbox is the easiest way to store, sync and share files online. File Sync 2GB of online storage for free, with up to 100GB available to paying customers. Sync files of any size or type. Sync Windows, Mac and Linux computers. Automaticall...
  • EaseUS Partition Master Free 12.0 27 April 2017
    As Partition Magic alternative, EASEUS Partition Master Home Edition is a FREE ALL-IN-ONE partition solution and disk management utility. It allows you to extend partition (especially for system drive), manage disk space easily, settle low disk space...

RSS detikInet

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

RSS detikOto

%d blogger menyukai ini: