Rabu, 20 April 2011

Program Mencari Nilai FPB

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

int main()
{
int m,n,r;
cout << "Masukkan nilai A : ";
cin >> m;
cout << "Masukan nilai B : " ;
cin >> n;
r = m%n;
while (r!=0)
{
m = n;
n = r;
r = m%n;
}
cout << "Faktor Persekutuan Terbesar dari A dan B adalah : " <<n<<endl;
getch();
}
Hasil:

Continue reading →

Program Bilangan Prima

0 komentar

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
int main()
{

int a, b, c, d, e;
cout<<"Masukkan Nilai 1 : ";
cin>>b;
cout<<"Masukkan Nilai 2 : ";
cin>>c;

cout<<"\nBilangan Prima Antara "<<b<<" dan "<<c<<" adalah : \n";

for(a=b+1, e=0;a<c;a++)
{
for(d=a;d>1;d--)
{
if( !(a%d) && a!=d )//bukan bilangan prima
{
goto skip;
}
}
printf("%d, ",a);
e++;

skip:;
}
printf("\r\n\nAda %d\r\n\r\n",e);
getch();
}
HasilL:
Continue reading →

Program Bilangan Deret

0 komentar

#include <iostream.h>
#include <conio.h>        
                class hitung
                {
                public:
                 int proses();
                 void input();
                private:
                 int n;
                 float rumus,jumlah,total;
                };
                 
                void hitung::input()
                {
                 cin>>n;
                 cout<<endl;
                }
                 
                int hitung::proses()
                {
                 jumlah=0;
                 total=0;
                 rumus=-1;
                 
                 for(int j=1; j<=n; j++)
                 {
                 rumus=(rumus*(-1));
                 total=rumus/j;
                 jumlah+=total;
                 if(j==1)
                 cout<<"("<<total<<")";
                 if(j>1)
                 cout<<"+("<<total<<")";
                 }
                cout<<endl<<endl<<"hasil penjumlahan deret = "<<jumlah;
                return jumlah;
                }
                 
                int main()
                {
                cout<<"program sederhana menghitung jumlah dari rumus 1-(1/2)+(1/3)-(1/4)+...+(1/n)"<<endl<<endl;
                cout<<"tentukan nilai n : ";
                hitung deret;
                deret.input();
                deret.proses();
                 getch();
                return 0;
                }
Hasil:
Continue reading →

Program Tahun Kabisat

0 komentar

#include <iostream.h>
#include <conio.h>
class kabisat {
                public:
void proses();
                private:
                int n;
                };
void kabisat::proses()
{
cout << "Menentukan tahun kabisat atau bukan"<<endl;
                cout<<"Masukkan tahun: ";
cin>>n;
                if (n % 4 != 0)
        cout << "Tahun " << n << " bukan tahun kabisat" << endl;
    else
        if ((n % 100 == 0) && (n % 400 != 0))
            cout << "Tahun " << n << " bukan tahun kabisat" << endl;
        else
            cout << "Tahun " << n << " tahun kabisat" << endl;
                }
int main()

{
               
               
                kabisat tahun;
               
                tahun.proses();
               
                getch();
                return 0;
               
}
Hasil:
Continue reading →

Program Menghitung Nilai N

0 komentar

#include <iostream.h>
#include <conio.h>
void cetak(int n)
{
    int i;
    for (i=1; i<=n; i++)
        cout << "Harga n = " << i << endl;
}

main() {
     int n;
     cout << "Masukkan harga n : "; cin >> n;
     cetak(n);
     getch();
     return 0;
}
Hasil:
Continue reading →

Program Hasil Pemangkatan

0 komentar

#include <iostream.h>
#include <conio.h>
main() {
     int x, y, i;
     int pangkat = 1;
     cout << "Menghitung hasil perpangkatan\n";
     cout << "Tulis sebuah bilangan : ";  cin >> x;
     cout << "Mau dipangkat berapa  : ";  cin >> y;
     for (i = 1; i<=y; i++)
            pangkat *= x;
     cout << x << " pangkat " << y << " = "  << pangkat;
     getch ();
     return 0;  
}
Hasil:
Continue reading →

Menghitung Nilai Fungsi X Integer&Float

0 komentar

#include <iostream.h>
#include <conio.h>
template<class T>
T tambah5(T x)
{
    return (x+5);
}
main() {
     int x;
     float y;    
     cout << "Masukkan harga x (integer) : "; cin >> x;
     cout << "Setelah masuk fungsi bernilai : " << tambah5(x) << endl;
     cout << "Masukkan harga x (float) : "; cin >> y;
     cout << "Setelah masuk fungsi bernilai : " << tambah5(y);
     getch();
     return 0;
}
Hasil:

Continue reading →

Menghitung Volum Bola

0 komentar

#include <iostream.h>
#include <conio.h>
class volume_bola {
public:
void volume();
void hitung();
private:
float v,r;
};
void volume_bola::volume(){
cout<<"PROGRAM MENGHITUNG VOLUME bola"<<endl;
cout<<"nilai r : "; cin>>r;
}
void volume_bola::hitung(){
v=4/3*(3.14*r*r*r);
cout<<"Volume Bola = " << v;
cout<<endl;
}
int main(){
volume_bola x;
x.volume();
x.hitung();
getch();
return 0;
}
Hasil:
Continue reading →
Selasa, 19 April 2011

Program Perkalian Dengan Cara Penjumlahan

0 komentar

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

main() {
     int a, b, jumlah=0;

     cout << "Program menghitung perkalian dengan cara penjumlahan\n";
     cout << "Masukkan nilai a : "; cin >> a;
     cout << "Masukkan nilai b : "; cin >> b;
     for (int i=1; i<=abs(b); i++)
        jumlah += a;
     if (b < 0) jumlah = -jumlah;
     cout << a << "x" << b << " = " << jumlah;
     getch ();
     return 0;
}
Hasil:
Continue reading →

Program Rekursif

0 komentar

#include <iostream.h>
#include <string.h>
#include <conio.h>
void balik(char *s)
{
     if (*s != '\0') {
         balik(&s[1]);
         cout << s[0];
     }
}
main() {
     char *kata = "Algoritma";
     balik(kata);
     getch();
     return 0;  
}
Hasil:
Continue reading →

Program Menghitung Nilai X

0 komentar

#include <iostream.h>
#include <conio.h>
int tambah5(int x)
{
    return (x+5);
}

main() {
     int x, y;
     cout << "Masukkan harga x : "; cin >> x;
     y = tambah5(x);
     cout << "Setelah masuk fungsi bernilai : " << y;
     getch();
     return 0;
     }
Hasil:
Continue reading →

Program Nilai

0 komentar


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

using namespace std;
int main(){
     ifstream filein;
     filein.open("nilai.dat");
     int nilai[10];
     for(int i=0; i<10; i++){
            
             filein>>nilai[i];
             cout<<"Nilai ke-"<<i+1<<"\t:"<<nilai[i]<<endl;
             }
             filein.close();
            getch();
            return 0;
}

Hasil:
   


Continue reading →

Program Bilangan

0 komentar

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

int main() {
     int i = 1;   // deklarasi dan pernyataan sederhana 
               
     while ((i <= 5)) {          //  awal pernyataan majemuk 
            cout << "Bilangan : " << i << "\n";          
                i++;                          //  kenaikan nilai i 
                }                                //  akhir pernyataan majemuk
    getch();
     return 0;
}
Hasil:
Continue reading →

Program Pemangkatan

0 komentar

#include <iostream.h>
#include <math.h>
#include <conio.h>
float pangkat(int x, int y)
{     return(exp(y*log(x)));  }
main() {
     float hasil;
     int a, b;
     cout << "Menghitung hasil perpangkatan\n";
     cout << "Tulis sebuah bilangan : "; cin >> a;
     cout << "Mau dipangkat berapa  : "; cin >> b;
     hasil = pangkat(a,b);
     cout << a << " pangkat " << b << " = "  << hasil;
     getch();
     return 0;  
}
Hasil:

Continue reading →

Program overloading

0 komentar

#include <iostream.h> 
#include <conio.h>
int max(int x, int y)
{
return (x > y ? x : y);
}

int max(int x, int y, int z)
{
int m = (x > y ? x : y);  // m = max(x,y)
return (z > m ? z : m);
}

int main()
{
    cout << "Maksimum 2 bilangan : " << max(99,77) << endl;
    cout << "Maksimum 3 bilangan : " << max(55,66,33);
    getch();
    return 0;
}
Hasil:
Continue reading →

Program Menghitung Titik Tengah

0 komentar

#include <iostream.h>
#include <conio.h>
class Titik{
      friend istream& operator>>(istream& ,Titik&);
      friend ostream& operator<<(ostream& ,Titik&);
      public:
             Titik();
             float titik1();
             float titik2();
      private:
             float x1, x2;
             float y1, y2;
             float TitikTengahx;
             float TitikTengahy;
             };
Titik::Titik(){
               }
float Titik :: titik1(){
                TitikTengahx=(x1+x2)/2;
                return TitikTengahx;
      }
float Titik :: titik2(){
      TitikTengahy=(y1+y2)/2;
      return TitikTengahy;
      }
istream& operator>>(istream& in, Titik& M){
         cout<<"PROGRAM MENGHITUNG TITIK TENGAH"<<endl;
         cout<<"masukkan nilai x1 dan x2 : ";
         in>>M.x1>>M.x2;
         cout<<"masukkan nilai y1 dan y2 : ";
         in>>M.y1>>M.y2;
         return in;
   }

ostream& operator<<(ostream& out, Titik& M){
        out<<"titik tengahnya adalah :("<<M.titik1()<<" , "<<M.titik2()<<")";
        return out;
   }
int main(){
        Titik x;
        cin>>x;
        cout<<x;
        getch ();
      return 0;
}
Hasil:

 
Continue reading →

Menghitung Banyak Data

0 komentar

#include <iostream.h>
#include <conio.h>
main() {
     int i, n, jumlah, x;
     float rata;
     cout << "Banyak data : ";   cin >> n;
     jumlah = 0;
     for (i = 1; i<=n; i++) {
          cout << "Data ke- : " << i;  cin >> x;
          jumlah += x;
     }  
     rata = (float) jumlah/n;
     cout << "Rata-rata = " << rata;
     getch ();
          return 0;  
}
Hasil:
Continue reading →

Program While Loop

0 komentar

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


int main(){
 int i=4;
 while(i>=4){
 cout<<""<<i;
 i--;
}
 getch();
 return 0;
}
Hasil:
Continue reading →

Program While Do

0 komentar

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


int main(){
 int i=1;
 do{
 cout<<""<<i;
 i--;
}while(i>= 1);
 getch();
 return 0;
}
Hasil:
Continue reading →
Senin, 18 April 2011

Program Loop For

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

int main(){
 int i;
 for(i=4;i>=1;i--)
 cout<<""<<i;
 getch();
 return 0;
}
Hasil:
Continue reading →

Program Perkalian

0 komentar

#include <iostream.h>
#include <math.h>
#include <conio.h>
int kali(int m, int n)
{    int i, hasil=0;
     for (i=1; i<=abs(n); i++)
           hasil += m;
     if (n<0) return(-hasil); else return(hasil);
}

main() {
     int a, b;
     cout << "Masukkan bilangan  : ";  cin >> a;
     cout << "Akan dikali dengan : ";  cin >> b;
     cout << "Nilai " << a << " x " << b << " = " << kali(a,b);
     getch();
     return 0;  
}
Hasil:
Continue reading →

Program Iteratif

0 komentar

#include <iostream.h>
#include <string.h>
#include <conio.h>
void balik(char *s)
{    int i;
     for (i=strlen(s)-1; i>=0; i--)
         cout << s[i];
}

main(){
     char *kata = "Algoritma";
     balik(kata);
     getch();
     return 0;  
}
Hasil:
Continue reading →

Labels