langkah-langkah:
1. Buka software aplikasi Dev C++ atau Codeblock
2. Klik Menu File, pilih New, pilih Project
3. Pilih Console Aplication, pilih Go
4. Pilih C++, Next
5. Beri nama project, lalu Next, kemudian Finish
6. Kemudian ketikkan sintax seperti berikut:
#include <iostream>
#include <conio.h>
#include <stdlib.h>
using namespace std;
int main()
{
menu:
int y,bts,out=0,t,angka=0,a,b;
char pilih, coba;
cout<<endl;
cout<<"=============================================="<<endl;
cout<<"| TUGAS |"<<endl;
cout<<"=============================================="<<endl;
cout<<"| Soal: |"<<endl;
cout<<"| 1. Bilangan Prima |"<<endl;
cout<<"| Misalkan: |"<<endl;
cout<<"| Input = 5 |"<<endl;
cout<<"| Output = 2 3 5 7 11 |"<<endl;
cout<<"| 2. Segitiga Bintang |"<<endl;
cout<<"| Misalkan: |"<<endl;
cout<<"| Input = 2 |"<<endl;
cout<<"| Output = 1 |"<<endl;
cout<<"| 1 2 |"<<endl;
cout<<"| 1 |"<<endl;
cout<<"=============================================="<<endl<<endl;
cout<<"Soal Pilihan Anda [1/2]= ";
cin>>y;
switch (y)
{
case 1:
system("cls");
cout<<endl;
cout<<"====================== SELAMAT MENCOBA ======================"<<endl<<endl;
cout<<"Masukkan Batas Nilai = ";
cin>>bts;
for(int out=0,angka=0;out<bts;angka++ )
{
if(angka==2||angka==3||angka==5||angka==7||angka==11)
{
t=1;
}
else
{
if(angka%2==0||angka==1)
{
t=0;
}
else
{
if(angka%3==0)
{
t=0;
}
else if(angka%5==0)
{
t=0;
}
else if(angka%7==0)
{
t=0;
}
else if(angka%11==0)
{
t=0;
}
else
{
t=1;
}
}
}
if(t==1)
{
out++;
cout<<angka<<" ";
}
}
cout<<endl<<endl;
break;
case 2:
system("cls");
cout<<endl;
cout<<"====================== SELAMAT MENCOBA ======================"<<endl<<endl;
cout<<"Masukkan Nilai Batas = ";
cin>>bts;
for(a=1;a<=bts;a++)
{
for(b=1;b<=a;b++)
cout<<b<<" ";
cout<<endl;
}
for(a=bts-1;a>=1;a--)
{
for(b=1;b<=a;b++)
cout<<b<<" ";
cout<<endl;
}
break;
default:
cout<<endl<<endl;
cout<<"S A L A H I N P U T"<<endl<<endl;
break;
}
cout<<endl<<endl;
cout<<"Coba lagi (Y/N) : ";
cin>>coba;
if (coba == 'y')
{
system("cls");
goto menu;
}
else
{
system("cls");
cout<<endl;
cout<<" Terima Kasih"<<endl<<endl<<endl<<endl<<endl;
cout<<" Oleh: "<<endl;
cout<<" Desty Septyani "<<endl;
cout<<" Teknik Informatika "<<endl;
}
return 0;
}
7. Kemudian klik menu Build, pilih Run / Build and Run
Selesai
Semoga bermanfaat
No comments:
Post a Comment