Program Menampilkan Deret Bilangan Prima - Perintah GOTO C/C++
Praktikum Perintah GOTO C/C++
Hasil running
#include <conio.h> #include <iostream> using namespace std; int prima (int n) { int i, jml; jml = 0; for (i = 1; i <= n; i++) { if (n % i == 0) { jml++; } } if (jml == 2) { return 0; } else { return 1; } } main () { int j, n, cacah; char lagi; lagi: cout << "\nMasukan batas bilangan : "; cin >> n; cout << "Berikut bilangan itu : " << endl; cacah = 0; for (j = 1; j <= n; j++) { if (prima(j) == 0) { cout << j << " "; cacah++; } } cout << "\nBanyaknya bilangan prima adalah : " << cacah << endl; getch (); cout << "Mau coba kembali [Y/T]"; cin >> lagi; getch (); if (lagi == 'Y' || lagi == 'y') { cout << "\n"; goto lagi; } if (lagi == 'T' || lagi == 't') { getch(); cout << "\nThank's by using this program'"; } }
Hasil running
0 Response to "Program Menampilkan Deret Bilangan Prima - Perintah GOTO C/C++"
Post a Comment