soal latihan
Terdapat sebuah mobil angkutan dengan kapasitas muatan =255kg.
Seorang petani akan membawa hasil pertaniannya ke kota dengan barang-barang sebagai berikut :
1.Wortel 20 kg : Rp .1 juta
2.Beras 150 kg : Rp .2 juta
3.Mangga 100 kg : Rp .1.5 juta
4.Sayuran 50 kg : Rp .1 juta
5.Bawang 50 kg : Rp .1.2 juta.
tentukan urutan barang yang dibawa petani agar optimal.
Jawaban:
by profit :
2,3,5,4,1
w1 x 1 + w2 x 2 + w3 x 3 + w4 x 4 + w5 x 5 =255
50.0 +150.1 +100.1 +50.0n +50x5=255
250+50 x5 =255
50 x5 =255-250
x5=5/50
x5=1/10
by weight :
1,5,4,3,2
w1 x 1 + w2 x 2 + w3 x 3 + w4 x 4 + w5 x 5 =255
20.1 + 150 x 2 + 100.1 + 150.1 + 50.1 =255
150.1 x 2 +220 =225
150. x 2 =255-220
x 2=35/150
x 2=7/30
fungsi perbandingan :
1,5,4,3,2
w1 x 1 + w2 x 2 + w3 x 3 + w4 x 4 + w5 x 5 =255
20.1 + 150.x 2+ 100.1 + 150.1+50.1 =255
150.1 x 2 + 220 =225
150. x 2 =225-220
x 2 =35/150
x 2 =7/30
pi max :
0,1,1,0,1/10
1.0 + 2.1 + 1,51 + 1.0 +1.2 .1/10 =3,62 juta
wi min :
1 + 2. 7/30 + 1,5 1 + 1 + 1,2 =5,16 juta
pi /wi max :
1 + 2.7/30 + 1,5 + 1 +1 +1,2 = 5,16 juta
Senin, 21 Desember 2015
Selasa, 15 Desember 2015
Menghitung Tahun Kabisat
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
cout<<"--------------------------------\n";
cout<<">>>>MENGHITUNG TAHUN KABISAT<<<<\n";
cout<<"--------------------------------\n";
int tahun,awal,akhir;
cout<<"Masukkan Tahun Awal : ";
cin>>awal;
cout<<"Masukkan Tahun Akhir: ";
cin>>akhir;
cout<<endl;
for(tahun=awal; tahun<=akhir; tahun++)
if(tahun%4==0)
{
cout<<"Tahun Kabisat : "<<tahun;
cout<<endl;
}
else
{
cout<<"Bukan Tahun Kabisat : "<<tahun;
cout<<endl;
}
system("pause");
return 0;
}

#include <iostream>
using namespace std;
int main()
{
cout<<"--------------------------------\n";
cout<<">>>>MENGHITUNG TAHUN KABISAT<<<<\n";
cout<<"--------------------------------\n";
int tahun,awal,akhir;
cout<<"Masukkan Tahun Awal : ";
cin>>awal;
cout<<"Masukkan Tahun Akhir: ";
cin>>akhir;
cout<<endl;
for(tahun=awal; tahun<=akhir; tahun++)
if(tahun%4==0)
{
cout<<"Tahun Kabisat : "<<tahun;
cout<<endl;
}
else
{
cout<<"Bukan Tahun Kabisat : "<<tahun;
cout<<endl;
}
system("pause");
return 0;
}
Menghitung dua Matrix
#include<iostream.h>
#include <conio.h>
#include <iomanip.h>
int i, j, baris, kolom, m1[10][10], m2[10][10], hasil[10][10];
void main()
{
clrscr();
cout << "=================================="<<endl;
cout << "Operasi Penjumlahan Matrix\n";
cout << "=================================="<<endl;
do
{
cout << "Jumlah Baris = "; cin>>baris;
cout << "Jumlah Kolom = "; cin>>kolom;
}
while((baris>10)||(kolom>10));
/* do
while(kolom>10);*/
cout << "\nMatrix A" << endl;
for(i=0;i<baris;i++)
for(j=0;j<kolom;j++)
{
cout <<"data [" << i << "," << j << "] = ";
cin>>m1[i][j];
}
cout << "\nMatrix B" << endl;
for(i=0;i<baris;i++)
for(j=0;j<kolom;j++)
{
cout <<"data [" << i << "," << j << "] = ";
cin>>m2[i][j];
}
for(i=0; i<baris;i++)
for(j=0; j<kolom; j++)
hasil[i][j] = m1[i][j] + m2[i][j];
cout << "\nHasilnya..." << endl;
cout << "Matrix A + Matrix B = Matrix C";
for(i=0; i< baris; i++)
{
cout<<'\n';
for(j=0; j<kolom; j++)
cout << setw(4) << m1[i][j];
cout << " ";
for(j=0; j<kolom; j++)
cout << setw(4) << m2[i][j];
cout << " ";
for(j=0; j<kolom; j++)
cout << setw(4) << hasil[i][j];
cout << endl;
}
getch();
}
#include <conio.h>
#include <iomanip.h>
int i, j, baris, kolom, m1[10][10], m2[10][10], hasil[10][10];
void main()
{
clrscr();
cout << "=================================="<<endl;
cout << "Operasi Penjumlahan Matrix\n";
cout << "=================================="<<endl;
do
{
cout << "Jumlah Baris = "; cin>>baris;
cout << "Jumlah Kolom = "; cin>>kolom;
}
while((baris>10)||(kolom>10));
/* do
while(kolom>10);*/
cout << "\nMatrix A" << endl;
for(i=0;i<baris;i++)
for(j=0;j<kolom;j++)
{
cout <<"data [" << i << "," << j << "] = ";
cin>>m1[i][j];
}
cout << "\nMatrix B" << endl;
for(i=0;i<baris;i++)
for(j=0;j<kolom;j++)
{
cout <<"data [" << i << "," << j << "] = ";
cin>>m2[i][j];
}
for(i=0; i<baris;i++)
for(j=0; j<kolom; j++)
hasil[i][j] = m1[i][j] + m2[i][j];
cout << "\nHasilnya..." << endl;
cout << "Matrix A + Matrix B = Matrix C";
for(i=0; i< baris; i++)
{
cout<<'\n';
for(j=0; j<kolom; j++)
cout << setw(4) << m1[i][j];
cout << " ";
for(j=0; j<kolom; j++)
cout << setw(4) << m2[i][j];
cout << " ";
for(j=0; j<kolom; j++)
cout << setw(4) << hasil[i][j];
cout << endl;
}
getch();
}
Langganan:
Postingan (Atom)