Ads 468x60px

Pages

Kamis, 03 Oktober 2013

Program Sederhana Dengan C++


Program Untuk Menghitung Luas dan Keliling Lingkaran:
Coding :
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>

void main ()
{
 clrscr;
float jari ,keliling ,luas;
const float pi= 3.14;



cout<<"==========================================================\n";
cout<<"|  Program untuk menghitung LUAS dan KELILING LINGKARAN  |\n";
cout<<"==========================================================\n";
cout<<"Masukan panjang jari_jari(r) : ";cin>>jari;
luas = pi * jari * jari;  //rumus Luas lingkaran
keliling = 2 * pi * jari;      //rumus keliling lingkaran
cout<<"\n";
cout<<"\n";
cout<<"===========================================================\n";
cout<<"Luas lingkaran adalah     : "<<luas <<"\n";
cout<<"Keliling lingkaran adalah : "<<keliling <<"\n";
cout<<"===========================================================\n";
cout<<"\n";
cout<<"\n";
cout<<"Tekan ENTER untuk KELUAR";
getch ();
}

Hasilnya seperti gambar dibawah ini :




Program Untuk Menghitung Luas dan Keliling Segi Empat
Coding :
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>

void main ()
{
 clrscr;
float pjg ,lbr ,luas ,keliling;

cout<<"=================================================\n";
cout<<"| Program untuk menghitung LUAS dan KELILING SEGI EMPAT    |\n";
cout<<"|                                                          |\n";
cout<<"=================================================\n";
cout<<" Masukan panjang panjang : ";cin>>pjg;
cout<<" Masukan panjang lebar   : ";cin>>lbr;
luas = pjg * lbr;  //rumus Luas lingkaran
keliling = 2 * (pjg+lbr);     //rumus keliling lingkaran
cout<<"\n ";
cout<<"\n ";
cout<<"\n ";
cout<<"\n";
cout<<"================================================\n";
cout<<" Hasil perhitungan        \n" ;
cout<<"\n";
cout<<" Keliling lingkaran adalah : "<<keliling <<"\n";
cout<<" Luas lingkaran adalah     : "<<luas <<"\n";
cout<<"================================================\n";
cout<<"\n";
cout<<"\n";
cout<<"Tekan ENTER untuk KELUAR";
getch ();
}

Hasilnya :                                    

Program Untuk Menampilkan Bilangan GANJIL dibawah (n) nilai dengan perulangan “FOR “:

Coding :
#include<iostream.h>
#include<conio.h>

void main()
{  clrscr;
  int bil, n ;
cout<<"==================================\n";
cout<<" Menampilkan Angka Ganjil dibawah nilai(n) \n";
cout<<"==================================\n";
cout<<"   Masukan Nilai n =   ";
cin>>n;
cout<<"==================================\n";
cout<<"Hasilnya adalah : \n";
cout<<" \n" ;
for (bil = 1; bil <n; bil+=2)
{
if (bil % 1==0) cout<< bil<<"\n";
}
cout<<"==================================\n";
cout<<" \n" ;
cout<<" \n" ;
cout<<" \n" ;
cout<<"Tekan ENTER untuk Keluar";
getche();
}

Haslinya:




Program Untuk Menampilkan Bilangan genap dibawah (n) nilai dengan perulangan “FOR “:

Coding :

#include<iostream.h>
#include<conio.h>


void main()
{  clrscr;
  int bil, n ;
cout<<"==================================\n";
cout<<" Menampilkan Angka Genap dibawah nilai(n) \n";
cout<<"=================================\n";
cout<<"   Masukan Nilai n =   ";
cin>>n;
cout<<"=================================\n";
cout<<"Hasilnya adalah : \n";
cout<<" \n" ;
for (bil = 1; bil <n; bil++)
{
if (bil % 2==0) cout<< bil<<"\n";
}
cout<<"=================================\n";
cout<<" \n" ;
cout<<" \n" ;
cout<<" \n" ;
cout<<"Tekan ENTER untuk Keluar";
getch();
}

Hasilnya:







Program Untuk Menampilkan Bilangan GANJIL dibawah (n) nilai dengan perulangan “WHILE “:

Coding :
#include<iostream.h>
#include<conio.h>


void main()
{
 clrscr;
int c=-1 ,n;
cout<<"=========================================\n";
cout<<"|   Angka Ganjil dibawah (n) nilai       |\n";
cout<<"=========================================\n";

cout<<" Masukan nilai : ";cin>>n;"\n";
cout<<"=========================================\n";
cout<<"Hasil : \n";
cout<<"\n";
while (c<n)

{
n-=1; c+=2; n++;
cout<<c<<"\n";
}
cout<<"=========================================\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"Tekan ENTER untuk Keluar\n";
getch();
}

Haslinya ;



Program Untuk Menampilkan Bilangan GENAP dibawah (n) nilai dengan perulangan “WHILE “:

Coding :
#include<iostream.h>
#include<conio.h>


void main()
{
 clrscr;
int c=0 ,n;
cout<<"=========================================\n";
cout<<"|   Angka Genap dibawah (n) nilai       |\n";
cout<<"=========================================\n";

cout<<" Masukan nilai : ";cin>>n;"\n";
cout<<"=========================================\n";
cout<<"Hasil : \n";
cout<<"\n";
while (c<n)

{
n-=1; c+=2; n++;
cout<<c<<"\n";
}
cout<<"=========================================\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"Tekan ENTER untuk Keluar\n";
getche();
}

 Hasilnya :


Program Untuk Menampilkan Bilangan GANJIL dibawah (n) nilai dengan perulangan “DO WHILE “:

Coding :
#include <iostream.h>
#include <conio.h>


void main ()
{
// Local variable declaration:
int c=1,n;
cout<<"=========================================\n";
cout<<"|   Angka Ganjil dibawah (n) nilai       |\n";
cout<<"=========================================\n";

cout<<" Masukan nilai : ";cin>>n;"\n";
cout<<"=========================================\n";
cout<<"Hasil : \n";
cout<<"\n";
do
{
cout<<c<<"\n";
n-=1; c+=2; n++;


}
while(c<n );
cout<<"=========================================\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"Tekan ENTER untuk Keluar\n";

getch();
}
Hasilnya :


Program Untuk Menampilkan Bilangan GENAP dibawah (n) nilai dengan perulangan “DO WHILE “:

Coding :
#include <iostream.h>
#include <conio.h>


void main ()
{
int c=0,n;
cout<<"=========================================\n";
cout<<"|   Angka Genap dibawah (n) nilai       |\n";
cout<<"=========================================\n";

cout<<" Masukan nilai : ";cin>>n;"\n";
cout<<"=========================================\n";
cout<<"Hasil : \n";
cout<<"\n";
do
{
n-=1; c+=2; n++;

cout<<c<<"\n";
}
while(c<n );
cout<<"=========================================\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"Tekan ENTER untuk Keluar\n";

getch();
}
Hasilnya :



0 komentar:

Posting Komentar