Rabu, 29 April 2015
Oerasi Penjumlahan Matrix
#include<cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
int i, j, k, baris, kolom, m1[10]
[10], m2[10]
[10], hasil[10]
[10];
//void main()
{
//system("cls");
cout << "Operasi pertambahan Matrix\n";
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]=0;
}
for (k=0;k<3;k++)
hasil[i][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;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
int i, j, k, baris, kolom, m1[10]
[10], m2[10]
[10], hasil[10]
[10];
//void main()
{
//system("cls");
cout << "Operasi pertambahan Matrix\n";
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]=0;
}
for (k=0;k<3;k++)
hasil[i][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;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
Selasa, 28 April 2015
knapsack
#include <cstdlib>
#include <iostream>
using namespace std;
void knapsack(int n, float weight[], float profit[], float capacity)
{
float x[20], tp= 0;
int i, j;
float u=capacity;
for (i=0;i<n;i++)
x[i]=0.0;
for (i=0;i<n;i++)
{
if(weight[i]>u)
break;
else
{
x[i]=1.0;
tp= tp+profit[i];
u=u-weight[i];
}
}
if(i<n)
x[i]=u/weight[i];
tp= tp + (x[i]*profit[i]);
printf("\n The result vector is:- ");
for(i=0;i<n;i++)
printf("%f\t",x[i]);
printf("\m Maximum profit is:- %f", tp);
}
int main()
{
float weight[20], profit[20], capacity;
int n, i ,j;
float ratio[20], temp;
printf ("\n Enter the no. of objects:- ");
scanf ("%d", &n);
printf ("\n Enter the wts and profits of each object:- ");
for (i=0; i<n; i++)
{
scanf("%f %f", &weight[i], &profit[i]);
}
printf ("\n enter the capacityacity of knapsack:- ");
scanf ("%f", &capacity);
for (i=0; i<n; i++)
{
ratio[i]=profit[i]/weight[i];
}
for(i=0; i<n; i++)
{
for(j=i+1;j< n; j++)
{
if(ratio[i]<ratio[j])
{
temp= ratio[j];
ratio[j]= ratio[i];
ratio[i]= temp;
temp= weight[j];
weight[j]= weight[i];
weight[i]= temp;
temp= profit[j];
profit[j]= profit[i];
profit[i]= temp;
}
}
}
knapsack(n, weight, profit, capacity);
system("PAUSE");
return EXIT_SUCCESS;
}
Outputnya seperti ini. :
#include <iostream>
using namespace std;
void knapsack(int n, float weight[], float profit[], float capacity)
{
float x[20], tp= 0;
int i, j;
float u=capacity;
for (i=0;i<n;i++)
x[i]=0.0;
for (i=0;i<n;i++)
{
if(weight[i]>u)
break;
else
{
x[i]=1.0;
tp= tp+profit[i];
u=u-weight[i];
}
}
if(i<n)
x[i]=u/weight[i];
tp= tp + (x[i]*profit[i]);
printf("\n The result vector is:- ");
for(i=0;i<n;i++)
printf("%f\t",x[i]);
printf("\m Maximum profit is:- %f", tp);
}
int main()
{
float weight[20], profit[20], capacity;
int n, i ,j;
float ratio[20], temp;
printf ("\n Enter the no. of objects:- ");
scanf ("%d", &n);
printf ("\n Enter the wts and profits of each object:- ");
for (i=0; i<n; i++)
{
scanf("%f %f", &weight[i], &profit[i]);
}
printf ("\n enter the capacityacity of knapsack:- ");
scanf ("%f", &capacity);
for (i=0; i<n; i++)
{
ratio[i]=profit[i]/weight[i];
}
for(i=0; i<n; i++)
{
for(j=i+1;j< n; j++)
{
if(ratio[i]<ratio[j])
{
temp= ratio[j];
ratio[j]= ratio[i];
ratio[i]= temp;
temp= weight[j];
weight[j]= weight[i];
weight[i]= temp;
temp= profit[j];
profit[j]= profit[i];
profit[i]= temp;
}
}
}
knapsack(n, weight, profit, capacity);
system("PAUSE");
return EXIT_SUCCESS;
}
Outputnya seperti ini. :
Kamis, 16 April 2015
Senin, 13 April 2015
Biodataku
Nama : | lalu arie kusuma wardani||
Tempat/Tanggal Lahir : | lombok 06 mei 1993 | |
Alamat : | lombok | |
hobby : | music : | |
Pendidikan saat ini : | UAD Universitas Ahmad Daahlan |