Archive for the ‘C++’ Category

DEV C++ Mencocokkan Jawaban

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

char kunci[11],jawaban[6][11];
int  tot[6],i,j;
main()
{
j=1;
while(j<=10)
{
cout<<“Kunci soal no “<<j<<” =”;
cin>>kunci[j];
j=j+1;
}
cout<<“\n”;
i=1;
while(i<=5)
{
cout<<“Mahasiswa ke “<<i<<“\n”;
j=1;
while(j<=10)
{
cout<<“Jawaban soal no “<<j<<” = “;
cin>>jawaban[i][j];
j=j+1;
}
i=i+1;
cout<<“\n”;
}
i=1;
while(i<=5)
{
tot[i]=0;
j=1;
while(j<=10)
{
if(jawaban[i][j]==kunci[j])
{
tot[i]=tot[i]+10;
}
j=j+1;
}
i=i+1;
}                             
i=1;
while(i<=5)
{
cout<<“Mahasiswa ke “<<i<<“\n”;
cout<<“Nilai =”<<tot[i]<<“\n”;
i=i+1;
}
getch();
}

Iklan

DEV C++ Matriks (2) Menghitung Pembelian

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
int hrg[5],PBL[4][5],tot[4],bayar[4],i,j;
main()
{
j=1;
while(j<=4)
{
cout<<“Harga barang jenis [“<<j<<“]=”;
cin>>hrg[j];
j=j+1;
}
cout<<“\n”;
i=1;
while(i<=3)
{
j=1;
while(j<=4)
{
cout<<“Banyak [“<<i<<“,”<<j<<“]=”;
cin>>PBL[i][j];
j=j+1;
}
cout<<“\n”;
i=i+1;
}
i=1;
while(i<=3)
{
bayar[i]=0;
j=1;
while(j<=4)
{
tot[j]=PBL[i][j]*hrg[j];
bayar[i]=bayar[i]+tot[j];
j=j+1;
}
i=i+1;
}
i=1;
while(i<=3)
{
cout<<“Total bayar [“<<i<<“]=”<<bayar[i]<<“\n”;
i=i+1;
}
getch();
}

DEV C++ Matriks (1)

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
int A[4][5],i,j;
main()
{
i=1;
while(i<=3)
{
j=1;
while(j<=4)
{
cout<<“A [“<<i<<“,”<<j<<“] =”;
cin>>A[i][j];
j=j+1;
}
cout<<“\n”;
i=i+1;
}
i=1;
while(i<=3)
{
j=1;
while(j<=4)
{
cout<<A[i][j]<<” “;
j=j+1;
}
cout<<“\n”;
i=i+1;
}
getch();
}

DEV C++ Loop Dalam Loop (6)

Tampilanya ini

100 95 90 85

80 75 70

65 60

55

syntaxnya gini lho..

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

float  i,j,bil,k,l,m;
main()
{
m=100;
l=20;
k=4;
i=1;
while(i<=4)
{
j=k;
bil=m;
while(j>=1)
{
cout<<bil<<” “;
bil=bil-5;
j=j-1;
}
cout<<“\n”;
m=m-l;
l=l-5;
k=k-1;
i=i+1;
}
getch();
}

DEV C++ Loop Dalam Loop (5)

tampilannya kayak gini

10

15 20

20 25 30

25 30 35 40

kalo syntaxnya gini lho

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

float  i,j,bil,k;
main()
{
k=10;
i=1;
while(i<=4)
{
j=1;
bil=k;
while(j<=i)
{
cout<<bil<<” “;
bil=bil+5;
j=j+1;
}
cout<<“\n”;
k=k+5;
i=i+1;
}
getch();
}

DEV C++ Loop Dalam Loop (4)

Tampilannya kayak gini

90

90 85

90 85 80

90 85 80 75

 

kalo ini syntaxnya

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

float  i,j,bil;
main()
{
i=1;
while(i<=4)
{
j=1;
bil=90;
while(j<=i)
{
cout<<bil<<” “;
bil=bil-5;
j=j+1;
}
cout<<“\n”;
i=i+1;
}
getch();
}

DEV C++ Loop Dalam Loop (3)

Tampilannya kayak gini

10 20 30 40 50

10 20 30 40

10 20 30

10 20

10

 

kalo syntaxnya gini

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

float  i,j,bil,k;
main()
{
k=5;
i=1;
while(i<=5)
{
j=k;
bil=10;
while(j>=1)
{
cout<<bil<<” “;
bil=bil+10;
j=j-1;
}
cout<<“\n”;
k=k-1;
i=i+1;
}
getch();
}