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 )

Foto Google+

You are commenting using your Google+ 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 )

w

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

  • Firefox 60.0 Beta 15 24 April 2018
    Mozilla Firefox is a fast, light and tidy open source web browser. At its public launch in 2004 Mozilla Firefox was the first browser to challenge Microsoft Internet Explorer’s dominance. Since then, Mozilla Firefox has consistently featured in the t...
  • Origin 10.5.17.52805 24 April 2018
    Origin lets you purchase and play EA games - any time and any place you want. With the in-game overlay, you can browse the web while playing select games. Origin's social features allow you to create a profile, connect and chat with your friends, sh...
  • Ace Utilities 6.3.0 24 April 2018
    Ace Utilities is a collection of tools to optimize and speedup your system performance. It contains utilities to clean the system registry, temporary files on your disks, erase unwanted applications and clear your Internet browser history, cache, a...
  • Deep Freeze Standard 8.38 24 April 2018
    Deep Freeze, as the name suggests is software designed to 'freeze' your system so that no matter what changes occur, they aren't permanent and can be reversed at the click of a button. Deep Freeze is a good choice for a variety of PC problems....
  • GeoGebra 6.0.458.0 24 April 2018
    GeoGebra is a free dynamic mathematics software tool for all levels of advanced education. The application combines geometry, algebra, spreadsheets, graphing, statistics and calculus and bundles them into one easy-to-use package. Users can use G...

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: