Rabu, 14 Oktober 2015

Refleksi Struktur Data 1



1.Program pemilihan masuk kuliah atau tidak 

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{

int bangun;

cout<<"Jam Berapa anda bangun?";
cin>>bangun;

if(bangun<5){
cout<<"Saya bisa kuliah tepat waktu"<<endl;}
else{
cout<<"Saya Tidur Lagi"<<endl;}

system("PAUSE");
return EXIT_SUCCESS;
}





2. Program Mencetak Bilangan 1 - 10 Dengan Perulangan For

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;

int main(int argc, char** argv) {

for(int i=1;i<=10;i++)
cout<<i<<endl;
return 0;
}



3. Program Mencetak Bilangan 1 - 10 Dengan Perulangan While

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;

int main(int argc, char** argv) {

int i=1;

while(i<=10){
cout<<i<<endl;
i++;
}
return 0;
}


4. Program Mencetak Bilangan 1 - 10 Dengan Perulangan Do While

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;

int main(int argc, char** argv) {

int i=1;

do{
cout<<i<<endl;
i++;
}
while(i<=10);

return 0;
}


5. Program Mencetak Bilangan Berurutan Dengan Fungsi

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;

void cetak(int a,int b){
for(int i=a;i<=b;i++)
cout<<"i = "<<i<<endl;
}

int main(int argc, char** argv) {

cetak (20,37);

return 0;
}



6. Program Menjumlahkan Setiap Bilangan Berurutan Dengan Fungsi

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;

int tambah(int c,int d){

int total=0;

for(int i=c;i<=d;i++)
total = total + i;

cout<<"Total = "<<total;
}

int main(int argc, char** argv) {

tambah (20,37);

return 0;
}



7. Program Menukar Bilangan Dengan Fungsi

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;

void tukarkan(int a,int b){

cout<<"Sebelum ditukar a = "<<a<<", dan b = "<<b<<endl;
int temp;
temp = a;
a = b;
b = temp;

cout<<"Setelah ditukar a = "<<a<<", dan b = "<<b;

}

int main(int argc, char** argv) {

int c=5, d=7;

tukarkan(c,d);

return 0;

}

Tidak ada komentar:

Posting Komentar