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

  • Opera 43.0.2442.991 22 Februari 2017
    Opera is a secure web browser that is both fast and rich in features. It has a slick interface that embraces a modern, minimalist look, coupled with stacks of tools to make browsing more enjoyable. These include such tools as Speed Dial, which houses...
  • Acronis True Image 2017 Build 8029 22 Februari 2017
    Acronis True Image 2017 is a new, multi-platform edition of the trusted backup tool. The application can work with both local and cloud storage, and can be configured to backup your whole disk or just single files or folders. It brings faster disk ...
  • Kindle for PC 1.19.3 Build 46099 22 Februari 2017
    Kindle for PC is a free application that lets you read Kindle books on your PC. Read Kindle Books on Your Computer Get the best reading experience available on your PC. No Kindle required. Access your Kindle books even if you don't have your Kin...
  • Far Manager 3.0.4900.0 22 Februari 2017
    Far Manager is an application for managing files and archives in Windows operating systems. Far Manager works in text mode and provides a simple and intuitive interface for performing actions. Key Features Include: Viewing files and directories; ...
  • Adobe Acrobat Reader DC 2015.023.20070 22 Februari 2017
    Adobe Acrobat Reader DC is the industry standard for viewing, printing, signing and commenting on PDF documents. It's the only PDF viewer available*, which is able to open and interact with all types of PDF content, including forms and multimedia. ...

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: