#include <cstdlib>
#include <iostream>
using namespace std;
class Madis{ //deklarasi kelas
public:
void pilih(); //pendeklarasian fungsi
pilihan
void permutasi(); //pendeklarasian fungsi
permutasi
void kombinasi(); //pendeklarasian fungsi
kombinasi
private:
int q[100];
};
void Madis::pilih(){
int n;
cout<<"\n1. Permutasi\n2. kombinasi";
cout<<"\n\npilihan anda : ";
cin>>n;
if(n==1)permutasi();
if(n==2)kombinasi();
else cout<<"\n\n***selesai***\n\n";
}
void Madis::permutasi(){
// system("cls");
int n,N,k,K,p;
cout<<"\nMasukkan nilai n=";cin>>n;
cout<<"Masukkan nilai r=";cin>>k;
if(k>n){cout<<"\nNilai r harus kutang dari
n";permutasi();}
p=n-k;
N=fak(n);K=fak(p);
[1]
cout<<"\nMaka hasil permutasi : "<<N/K;
cout<<"\n\n";pilih();
}
void Madis::kombinasi(){
// system("cls");
int n,N=1,k,K=1,p,P=1;
cout<<"\nMasukkan nilai n=";cin>>n;
cout<<"Masukkan nilai r=";cin>>k;
if(k>n){cout<<"\nNilai r harus kutang dari
n";permutasi();}
p=n-k;N=fak(n);K=fak(k);cout<<"\n(n-r)!->
";P=fak(p); [2]
cout<<"\nMaka hasil kombinasi : "<<N/(K*P);
[3]
cout<<"\n\n";pilih();
}
int main(int argc, char *argv[]) //fungsi main
{
Madis z;
z.pilih();
system("PAUSE");
return EXIT_SUCCESS;
}
TugasDP
Senin, 17 Juni 2019
#include<iostream.h>
#include <conio.h>
#include <iomanip.h>
int i, j, k, baris, kolom, m1[10]
[10], m2[10]
[10], hasil[10]
[10];
void main()
{
clrscr();
cout << "Operasi pertambahan Matrix\n";
do
{
cout << "Jumlah Baris = "; cin>>baris;
cout << "Jumlah Kolom = "; cin>>kolom;
}
while((baris>10)||(kolom>10)); [1]
/* 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++) [2]
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]; [3]
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]; [4]
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, k, baris, kolom, m1[10]
[10], m2[10]
[10], hasil[10]
[10];
void main()
{
clrscr();
cout << "Operasi pertambahan Matrix\n";
do
{
cout << "Jumlah Baris = "; cin>>baris;
cout << "Jumlah Kolom = "; cin>>kolom;
}
while((baris>10)||(kolom>10)); [1]
/* 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++) [2]
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]; [3]
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]; [4]
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();
}
Selasa, 28 Mei 2019
#include<iostream>
#include<conio.h>
using namespace std;
main(){
bool ketemu,nolsemua;
int matrix[100] [100];
int i,j,jumlah_simpul,jumlah_sisi,asal,tujuan;
//inisialisasi matrix
cout<<"jumlah simpul:";
cin>>jumlah_simpul;
cout<<"jumlah_sisi:";
cin>>jumlah_sisi;
for (i=1;i<=jumlah_simpul;i++)
for (j=1;j<=jumlah_simpul;j++)
matrix[i][j]=0;
//isi matrix sesuai input graf
for (i=1;i<=jumlah_sisi;i++){
cout<<"simpul asal:";
cin>>asal;
cout<<"simpul tujuan:";
cin>>tujuan;
matrix[asal][tujuan]=1;
matrix[tujuan][asal]=1; }
//telusuri graf i=1;nolsemua=false;
while (i<=jumlah_simpul && !nolsemua){
j=1;ketemu=false;
while (j<=jumlah_simpul && !ketemu){
if (matrix[i][j]==1)
ketemu=true;
else
j++;
}
if (!ketemu)
nolsemua=true;
else
i++;
}
if(nolsemua)
cout<<"graf tidak terhubung";
else cout<<"graf terhubung";
getch();
}
#include<conio.h>
using namespace std;
main(){
bool ketemu,nolsemua;
int matrix[100] [100];
int i,j,jumlah_simpul,jumlah_sisi,asal,tujuan;
//inisialisasi matrix
cout<<"jumlah simpul:";
cin>>jumlah_simpul;
cout<<"jumlah_sisi:";
cin>>jumlah_sisi;
for (i=1;i<=jumlah_simpul;i++)
for (j=1;j<=jumlah_simpul;j++)
matrix[i][j]=0;
//isi matrix sesuai input graf
for (i=1;i<=jumlah_sisi;i++){
cout<<"simpul asal:";
cin>>asal;
cout<<"simpul tujuan:";
cin>>tujuan;
matrix[asal][tujuan]=1;
matrix[tujuan][asal]=1; }
//telusuri graf i=1;nolsemua=false;
while (i<=jumlah_simpul && !nolsemua){
j=1;ketemu=false;
while (j<=jumlah_simpul && !ketemu){
if (matrix[i][j]==1)
ketemu=true;
else
j++;
}
if (!ketemu)
nolsemua=true;
else
i++;
}
if(nolsemua)
cout<<"graf tidak terhubung";
else cout<<"graf terhubung";
getch();
}
Senin, 20 Mei 2019
<h2>Abdul Afif</h2>
<h2>1800018410</h2>
<div class="table-responsive">
<table class="table" border="1">
<thead>
<tr>
<th>Kalimat</th>
<th>Strlen</th>
<th>Strtolower</th>
<th>Strtoupper</th>
<th>Date</th>
</tr>
</thead>
<?php
$kalimat = "yogyakarta";
$strlen = strlen($kalimat);
$strtolower = strtolower($kalimat);
$strtoupper = strtoupper($kalimat);
$date = date('l, d F Y');
?>
<?php
$kalimat2 = "kota";
$strlen2 = strlen($kalimat2);
$strtolower2 = strtolower($kalimat2);
$strtoupper2 = strtoupper($kalimat2);
$date2 = date('l, d F Y');
?>
<?php
$kalimat3 = "pendidikan";
$strlen3 = strlen($kalimat3);
$strtolower3 = strtolower($kalimat3);
$strtoupper3 = strtoupper($kalimat3);
$date3 = date('l, d F Y');
?>
<tbody>
<tr>
<td><?php echo $kalimat; ?></td>
<td><?php echo $strlen; ?></td>
<td><?php echo $strtolower; ?></td>
<td><?php echo $strtoupper; ?></td>
<td><?php echo $date; ?></td>
</tr>
<tr>
<td><?php echo $kalimat2; ?></td>
<td><?php echo $strlen2; ?></td>
<td><?php echo $strtolower2; ?></td>
<td><?php echo $strtoupper2; ?></td>
<td><?php echo $date2; ?></td>
</tr>
<tr>
<td><?php echo $kalimat3; ?></td>
<td><?php echo $strlen3; ?></td>
<td><?php echo $strtolower3; ?></td>
<td><?php echo $strtoupper3; ?></td>
<td><?php echo $date3; ?></td>
</tr>
</tbody>
</table>
</div>
<h2>1800018410</h2>
<div class="table-responsive">
<table class="table" border="1">
<thead>
<tr>
<th>Kalimat</th>
<th>Strlen</th>
<th>Strtolower</th>
<th>Strtoupper</th>
<th>Date</th>
</tr>
</thead>
<?php
$kalimat = "yogyakarta";
$strlen = strlen($kalimat);
$strtolower = strtolower($kalimat);
$strtoupper = strtoupper($kalimat);
$date = date('l, d F Y');
?>
<?php
$kalimat2 = "kota";
$strlen2 = strlen($kalimat2);
$strtolower2 = strtolower($kalimat2);
$strtoupper2 = strtoupper($kalimat2);
$date2 = date('l, d F Y');
?>
<?php
$kalimat3 = "pendidikan";
$strlen3 = strlen($kalimat3);
$strtolower3 = strtolower($kalimat3);
$strtoupper3 = strtoupper($kalimat3);
$date3 = date('l, d F Y');
?>
<tbody>
<tr>
<td><?php echo $kalimat; ?></td>
<td><?php echo $strlen; ?></td>
<td><?php echo $strtolower; ?></td>
<td><?php echo $strtoupper; ?></td>
<td><?php echo $date; ?></td>
</tr>
<tr>
<td><?php echo $kalimat2; ?></td>
<td><?php echo $strlen2; ?></td>
<td><?php echo $strtolower2; ?></td>
<td><?php echo $strtoupper2; ?></td>
<td><?php echo $date2; ?></td>
</tr>
<tr>
<td><?php echo $kalimat3; ?></td>
<td><?php echo $strlen3; ?></td>
<td><?php echo $strtolower3; ?></td>
<td><?php echo $strtoupper3; ?></td>
<td><?php echo $date3; ?></td>
</tr>
</tbody>
</table>
</div>
php pertemuan 9
<h2>Abdul Afif</h2>
<h2>1800018410</h2>
<div class="table-responsive">
<table class="table" border="1">
<thead>
<tr>
<th>Kalimat</th>
<th>Strlen</th>
<th>strpos</th>
<th>Strtolower</th>
<th>Strtoupper</th>
<th>Date</th>
</tr>
</thead>
<?php
$kalimat = "Universitas";
$strlen = strlen($kalimat);
$strpos = strpos($kalimat,"n");
$strtolower = strtolower($kalimat);
$strtoupper = strtoupper($kalimat);
$date = date("1");
?>
<?php
$kalimat2 = "Ahmad";
$strlen2 = strlen($kalimat2);
$strpos = strpos($kalimat,"n");
$strtolower2 = strtolower($kalimat2);
$strtoupper2 = strtoupper($kalimat2);
$date = date("H:i:s");
?>
<?php
$kalimat3 = "Dahlan";
$strlen3 = strlen($kalimat3);
$strtolower3 = strtolower($kalimat3);
$strtoupper3 = strtoupper($kalimat3);
$date = date("H:i:s");
?>
<tbody>
<tr>
<td><?php echo $kalimat; ?></td>
<td><?php echo $strlen; ?></td>
<td><?php echo $strtolower; ?></td>
<td><?php echo $strtoupper; ?></td>
<td><?php echo $date; ?></td>
</tr>
<tr>
<td><?php echo $kalimat2; ?></td>
<td><?php echo $strlen2; ?></td>
<td><?php echo $strtolower2; ?></td>
<td><?php echo $strtoupper2; ?></td>
<td><?php echo $date; ?></td>
</tr>
<tr>
<td><?php echo $kalimat3; ?></td>
<td><?php echo $strlen3; ?></td>
<td><?php echo $strtolower3; ?></td>
<td><?php echo $strtoupper3; ?></td>
<td><?php echo $date; ?></td>
</tr>
</tbody>
</table>
</div>
<h2>1800018410</h2>
<div class="table-responsive">
<table class="table" border="1">
<thead>
<tr>
<th>Kalimat</th>
<th>Strlen</th>
<th>strpos</th>
<th>Strtolower</th>
<th>Strtoupper</th>
<th>Date</th>
</tr>
</thead>
<?php
$kalimat = "Universitas";
$strlen = strlen($kalimat);
$strpos = strpos($kalimat,"n");
$strtolower = strtolower($kalimat);
$strtoupper = strtoupper($kalimat);
$date = date("1");
?>
<?php
$kalimat2 = "Ahmad";
$strlen2 = strlen($kalimat2);
$strpos = strpos($kalimat,"n");
$strtolower2 = strtolower($kalimat2);
$strtoupper2 = strtoupper($kalimat2);
$date = date("H:i:s");
?>
<?php
$kalimat3 = "Dahlan";
$strlen3 = strlen($kalimat3);
$strtolower3 = strtolower($kalimat3);
$strtoupper3 = strtoupper($kalimat3);
$date = date("H:i:s");
?>
<tbody>
<tr>
<td><?php echo $kalimat; ?></td>
<td><?php echo $strlen; ?></td>
<td><?php echo $strtolower; ?></td>
<td><?php echo $strtoupper; ?></td>
<td><?php echo $date; ?></td>
</tr>
<tr>
<td><?php echo $kalimat2; ?></td>
<td><?php echo $strlen2; ?></td>
<td><?php echo $strtolower2; ?></td>
<td><?php echo $strtoupper2; ?></td>
<td><?php echo $date; ?></td>
</tr>
<tr>
<td><?php echo $kalimat3; ?></td>
<td><?php echo $strlen3; ?></td>
<td><?php echo $strtolower3; ?></td>
<td><?php echo $strtoupper3; ?></td>
<td><?php echo $date; ?></td>
</tr>
</tbody>
</table>
</div>
Minggu, 19 Mei 2019
array 2 dimensi
#include<iostream>
#define max 100
using namespace std;
int main(){
int a[max][max];
int b[max][max];
int n;
cout<<"masukan nnnya =";cin>>n;
cout<<"input"<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<"baris ke- "<<i+1<<"kolom ke - "<<j+1<<" : ";
cin>>a[i][j];
}
}
cout<<"input 2"<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<"baris ke- "<<i+1<<"kolom ke - "<<j+1<<" : ";
cin>>b[i][j];
}
}
cout<<"\n output"<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
cout<<"\n output 2"<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<b[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}
#define max 100
using namespace std;
int main(){
int a[max][max];
int b[max][max];
int n;
cout<<"masukan nnnya =";cin>>n;
cout<<"input"<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<"baris ke- "<<i+1<<"kolom ke - "<<j+1<<" : ";
cin>>a[i][j];
}
}
cout<<"input 2"<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<"baris ke- "<<i+1<<"kolom ke - "<<j+1<<" : ";
cin>>b[i][j];
}
}
cout<<"\n output"<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
cout<<"\n output 2"<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<b[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
}
Senin, 13 Mei 2019
#include <iostream>
#include <conio.h>
using namespace std;
int main(){
const int Ar[7] = {2,4,6,8,9,14,30};
int tar;
cout<<"masukan data yang dicari : ";
cin>>tar;
int awal=0, akhir=7, tengah;
while (awal <= akhir)
{ tengah = (awal + akhir)/2;
if (tar > Ar[tengah] )
{ awal = tengah + 1; }
else if (tar < Ar[tengah])
{akhir= tengah - 1;}
else {awal = akhir +1;
}
}
if (tar == Ar[tengah])
{cout<<" Index, Ke- "<<tengah+1<<endl;
}
else {
cout<<"target tidak ditemukan "<<endl;
}
getch();
}
#include <conio.h>
using namespace std;
int main(){
const int Ar[7] = {2,4,6,8,9,14,30};
int tar;
cout<<"masukan data yang dicari : ";
cin>>tar;
int awal=0, akhir=7, tengah;
while (awal <= akhir)
{ tengah = (awal + akhir)/2;
if (tar > Ar[tengah] )
{ awal = tengah + 1; }
else if (tar < Ar[tengah])
{akhir= tengah - 1;}
else {awal = akhir +1;
}
}
if (tar == Ar[tengah])
{cout<<" Index, Ke- "<<tengah+1<<endl;
}
else {
cout<<"target tidak ditemukan "<<endl;
}
getch();
}
Langganan:
Postingan (Atom)