IT Solution

Tuesday 27 August 2013

Program c++ faktorial

August 27, 2013 Posted by Bops No comments
Struktur data (Semester 3)
Faktorial program
poted by: Nazih

#include<iostream>
using namespace std;
        int faktorial(int x){
                int b = 1;
                if(x-1 > 0){
                        b= faktorial(x-1);
                }
                return x * b;
        }
int main(){
        int angka;
        cout << "Masukan angka" << endl;
        cin >> angka;
        int hasil = faktorial(angka);
        cout << angka << " faktorial adalah : "<< hasil << endl;
        return 0;
}

Program c++ Struct

August 27, 2013 Posted by Bops No comments
Struktur Data (Semester 3)
Program Struct_Mobil
 Posted by: Muhammad Nazih

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
void cetak(); //--soal 1c
typedef struct Mobil{ //--soal 1a
        string seri;
        string warna;
        float harga;
        Mobil(string s,string w,float h){               //--soal 1b
                seri=s;
                warna=w;
                harga=h;
                }
        Mobil(){
        }

}Honda,Toyota;
//variable global
Mobil data_mobil[3];

int main(){
        Honda h1("jazz","merah",500000000);
        Honda h2("Avanza","hitam",800000000);
        Toyota t1("City","putih",200000000);
        //memasukan data ke dalam array
        data_mobil[0]=h1;
        data_mobil[1]=h2;
        data_mobil[2]=t1;
        cetak();
        return 0;
}
void cetak(){
 cout<<setw(30)<<"|Seri:"<<setw(10)<<"|Warna"<<setw(10)<<"|harga:"<<setw(10)<<"|"<< endl;
 for(int i=0;i<3;i++){
 cout<<setw(10)<<data_mobil[i].seri<<setw(10)<<data_mobil[i].warna<<setw(10)<<data_mobil[i].harga<<endl;
 }
}
-- INSERT --

Featured post

Game PC (BMW M3)