dari posting sebelumnya yang berisi pengertian interpreter,compiler,tipe
data dll, untuk kali ini saya akan melanjutkan ke tuttorial pemrograman
C++ untuk membuat program kalkulator sederhana dan program sederhana
dan program pengurutan data dengan 3 inputan data, langsung saja kita
membuat program seperti berikut
untuk program kalkulator sederhana adalah
#include <conio.h>
#include <iostream.h>
#include <stdio.h>
int main() {
int a;
int b;
cout << endl;
cout << "____________________________";
cout << endl;
cout << endl;
cout << "Intan Hajar Pratiwi";
cout << endl;
cout << endl;
cout << "20120335042";
cout << endl;
cout << "____________________________";
cout << endl;
cout << endl;
cout << "masukkan nilai a :" ;
cin >> a;
cout << "masukkan nilai b :" ;
cin >> b;
cout << endl;
cout << "____________________________";
cout << endl;
cout << endl;
cout << a << "+" << b << "=" << a+b;
cout << endl;
cout << a << "-" << b << "=" << a-b;
cout << endl;
cout << a << "*" << b << "=" << a*b;
cout << endl;
cout << a << "/" << b << "=" << a/b;
cout << endl;
cout << "____________________________";
getch();
}
untuk program pengurutan data adalah
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
int main(){
int a;
int b;
int c;
cout << endl;
cout << "____________________________";
cout << endl;
cout << endl;
cout << "Intan Hajar Pratiwi";
cout << endl;
cout << endl;
cout << "20120335042";
cout << endl;
cout << "____________________________";
cout << endl;
cout << endl;
cout<<"masukkan nilai a:";
cin>>a;
cout<<"masukkan nilai b:";
cin>>b;
cout<<"masukkan nilai c:";
cin>>c;
cout<<endl;
cout<<"____________________________";
cout<<endl;
cout<<endl;
if(b>a && c<b && c>a ){
cout<<"nilai besar : "<<b ;
cout<<endl;
cout<<"nilai kecil : "<<a ;
cout<<endl;
cout<<"nilai tengah: "<<c ;
}
if(b<a && a>c && c>b){
cout<<"nilai besar : "<<a ;
cout<<endl;
cout<<"nilai kecil : "<<b ;
cout<<endl;
cout<<"nilai tengah: "<<c ;
}
if(c>a && a<b && c>b){
cout<<"nilai besar : "<<c ;
cout<<endl;
cout<<"nilai kecil : "<<a ;
cout<<endl;
cout<<"nilai tengah: "<<b ;
}
if(b>a && a>c && c<a){
cout<<"nilai besar : "<<b ;
cout<<endl;
cout<<"nilai kecil : "<<c ;
cout<<endl;
cout<<"nilai tengah: "<<a ;
}
if(a>c && b>c && a>b){
cout<<"nilai besar : "<<a ;
cout<<endl;
cout<<"nilai kecil : "<<c ;
cout<<endl;
cout<<"nilai tengah: "<<b ;
}
if(c>a && a>b && b<c){
cout<<"nilai besar : "<<c ;
cout<<endl;
cout<<"nilai kecil : "<<b ;
cout<<endl;
cout<<"nilai tengah: "<<a ;
}
cout<<endl;
cout<<"____________________________";
getch();
}
Tidak ada komentar:
Posting Komentar