1. IF...ELSE
#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 score;
cout<<"score:";
cin>>score;
if(score>=70)
cout<<"Pas";
else
cout<<"Fail";
return 0;
}
output :
2. ARRAY 1 DIMENSI
#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 bilangan[5]={3,13,23,33,33};
cout<<bilangan[0]<<endl;
cout<<bilangan[1]<<endl;
cout<<bilangan[2]<<endl;
cout<<bilangan[3]<<endl;
cout<<bilangan[4]<<endl;
return 0;
}
output :
3. SWITCH CASE
#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 number;
cout<<"enter a positif interger:";
cin>>number;
switch(number){
case1:
cout<<"one!!";
cout<<"----------";
break;
case2:
cout<<"two!!";
break;
case3:
cout<<"Three!!";
break;
default:
cout<<"other";
break;}
cout<<"contoh";
//getch();
}
output :
Tidak ada komentar:
Posting Komentar