jawaban berdasarkan NPM 11111009
JAWABAN SOAL NOMOR 1
=====================
bilangan yang di urutkan : 1,1,1,1,1,0,0,9
i=0
j=4 bil = 1,1,1,1,1,0,0,9 (0<1) 1,1,1,1,0,0,1,9
j=3 bil = 1,1,1,1,0,0,1,9 (0<1) 1,1,1,0,0,1,1,9
j=2 bil = 1,1,1,0,0,1,1,9 (0<1) 1,1,0,0,1,1,1,9
j=1 bil = 1,1,0,0,1,1,1,9 (0<1) 1,0,0,1,1,1,1,9
-----------------------------------------------
i=1
j=4 bil = 1,0,0,1,1,1,1,9 (1>0) 1,1,1,0,0,1,9
j=3 bil = 1,1,1,0,0,1,9 (1>0) 1,1,0,0,1,1,9
j=2 bil = 1,1,0,0,1,1,9 (1>0) 1,0,0,1,1,1,9
---------------------------------------------
i=2
j=4 bil = 1,0,0,1,1,1,9 (1>0) 1,1,0,0,1,9
j=3 bil = 1,0,0,1,1,1,9 (1>0) 1,0,0,1,1,9
-------------------------------------------
i=3
j=3 bil = 1,0,0,1,1,9 (0<1) 0,0,1,1,9
j=4 bil = 0,0,1,1,9 (1>0) 1,0,0,1,9
------------------------------------------
i=4
j=4 bil = 1,0,0,1,9 ((1>0) 0,0,1,9
----------------------------------------
program:
program buble short
[spoiler=jawaban]
#include <iostream.h>
#include <conio.h>
void tampilkan_larik(int data[], int n)
{
int i;
for(i=0;i<n;i++)
cout<<data[i]<<" ";
cout<<"\n";
}
void buble_sort(int data[],int n)
{
int tahap,j,tmp;
for (tahap=1;tahap<n;tahap++)
{
for (j=0;j<n-tahap;j++)
if (data[j]>data[j+1])
{
//tukarkan
tmp=data[j];
data[j]=data[j+1];
data[j+1]=tmp;
}
cout<<"hasil tahap "<<tahap<<" : ";
tampilkan_larik (data,n);
}
}
int main()
{
const jum_data=8;
int i;
int data[]={1,1,1,1,1,0,0,9};
buble_sort(data, jum_data);
//hasil pengurutan
cout<<endl;
cout<<"Hasil Pengurutan: \n";
tampilkan_larik(data,jum_data);
getch();
}
menampilkan deret angka
#include<iostream.h>
#include<conio.h>
class segitiga{
public :
void rumus();
};
void main(){
segitiga x;
x.rumus();
getch();
}
void segitiga::rumus(){
for(int k=5; k>=1; k--){
for(int i=1;i<=k;i++){
cout<<i<<" ";
}
cout<<endl<<endl;
}
for(int i=1; i<6; i++){
for(int j=1; j<=i; j++){
cout<<j<<" ";
}
cout<<endl<<endl;
}
}
[/spoiler]
JAWABAN SOAL NO 2
==================
untuk jawaban no 2 ada beberapa bagian yang saya hilangkan...untuk menghindarkan bisa saja ada yg sama tugas nya sama saya ntar gak bakalan berjuang krn tinggal terima bersih...
12345
1234
123
12
1
1
12
123
1234
12345
[spoiler=jawaban]
#include"conio.h"
#include"stdio.h"
class segitiga{
public:
void rumus();
};
int main(){
segitiga x;
x.rumus();
getch();
}
void segitiga::rumus(){
for(int k=5; k>=1; k--){
................................{
printf("%......);
}
printf("\n");
}
for(int ....; i<6; ....){
for(int j=1; j<=i; j++){
printf(......);
}
printf("\n");
}
[/spoiler]
No comments:
Post a Comment