ALGORITMA PEMROGRAMAN TERSTRUKTUR
DEV C++ POLA SEGITIGA ,PERULANGAN, DAN DISKON
1.
#include
<iostream>
using namespace std;
int main(){
for(int
i=1; i>7; i--){
for(int
j=1; j<i; j++){
cout<<j;
}
cout<<endl;
}
return
0;
}
2.
#include
<iostream>
using namespace std;
int main()
{
cout
<<
"=================================================="<<endl;
cout
<< " SISTEM
INFORMASI "<<endl;
cout
<< " WAHYU
SOFIANDA"<<endl;
cout
<< "
0702203236
"<<endl;
cout
<<
"=================================================="<<endl;
for(int
i = 1; i<5; i++){
for(int
j = 5; j> i; j--){
cout
<< " ";
}
for(int
p = 0; p<i-1; p++){
for(int
j=0; j<=p; j++)
{
cout<<p+1;
}
}
cout<<i;
for
(int p = (i-1); p >= 1; p--){
for(int
j=1; j<=p; j++){
cout
<< p;
}
}
cout<<endl;
}
}
3.
#include
<iostream>
#include <conio.h>
using namespace std;
int main()
{
int
nilai;
cout<<"masukkan
batas nilai :";cin>>nilai;
cout<<endl;
for
(int a = nilai; a >= 1; a--)
{
for(int
b=1; b<=a; b++)
{
cout<<b<<"
";
}
cout<<endl;
}
return
0;
}
4.
#include
<iostream>
using namespace std;
int main () {
int
i, j;
for
(int i = 1; i<=5; i++ ) {
cout
<< i << " "; }
cout
<< endl;
for
(int i = 5; i>=1; i--) {
cout
<< i << " "; }
cout
<< endl;
for
(int i = 1; i<=9; i+=2 ) {
cout
<< i << " "; }
cout
<< endl;
for
(int i = 9; i>=1; i-=2) {
cout
<< i << " " ; }
cout
<< endl;
}
5.
#include
<iostream>
using namespace std;
int main () {
int i, j;
for (int i = 1; i<=9; i+=2 ) {
cout << i <<""; }
cout << endl;
for (int i = 2; i<=10; i+=2 ) {
cout << i <<"" ; }
cout << endl;
for (int i= 11; i<=17; i+=2 ) {
cout << i <<"";}
cout << endl;
for (int i = 12; i<=18; i+=2 ) {
cout << i <<"";}
cout << endl;
}
6.
#include
<iostream>
using namespace std;
int main(){
int
i, j;
for(i=1;
i<=5; i++)
for(j=1;
j<=i; j++)
cout
<< i;
return
0;
}
7.
#include
<iostream>
using namespace std;
int main(){
cout
<<"================================="<<endl;
cout
<<" SISTEM
INFORMASI "<<endl;
cout
<<" WAHYU
SOFIANDA "<<endl;
cout
<<"
0702203236 "<<endl;
cout
<<"================================="<<endl;
for(int
i=8;i>=-1;i--){
if
(i%2==0)
cout<<i<<"";
}
cout
<< endl;
for(int
i=1;i<=7;i++){
if
(i%2!=0)
cout<<""<<i;
}
}
8.
#include
<iostream>
using namespace std;
int main(){
cout
<<"================================="<<endl;
cout
<<" SISTEM
INFORMASI "<<endl;
cout
<<" WAHYU
SOFIANDA "<<endl;
cout
<<"
0702203236 "<<endl;
cout
<<"================================="<<endl;
for(int
i = 1; i <=8; i++){
cout<<
i;
}
cout << endl;
for (int i = 9; i >= 0; i--) {
if ((i % 2) == 0) {
for (int j = 1; j <= i; j++) {
if ((j % 2) == 0) {
cout << j;
}
}
cout
<<"\n";
} else {
for (int j = 1; j <= (i - 1); j++) {
if ((j % 2) == 1) {
cout << j;
}
}
cout
<<"\n";
}
}
}
9.
#include
<iostream>
using namespace std;
int main()
{
cout
<<
"=================================================="<<endl;
cout
<< " SISTEM
INFORMASI "<<endl;
cout
<< " WAHYU
SOFIANDA"<<endl;
cout
<< "
0702203236
"<<endl;
cout
<<
"=================================================="<<endl;
int bayar, akhir, diskon;
menu :
cout << "\nTOTAL PEMBAYARAN = ";
cin >> bayar;
if (bayar >= 350500){
if (bayar % 200 == 0){
diskon = bayar * 35 / 100;
akhir = bayar - diskon;
cout<<endl<<"selamat
anda mendapatkan diskon 35%"<<endl;
}
else{
diskon = bayar * 20 / 100;
akhir = bayar - diskon;
cout<<endl<<"selamat anda mendapatkan diskon
20%"<<endl;
}
}
if ((bayar >= 200000) && (bayar < 350500)){
if (bayar % 200 == 0){
diskon = bayar * 25 / 100;
akhir = bayar - diskon;
cout<<endl<<"selamat
anda mendapatkan diskon 25%"<<endl;
}
else{
diskon = bayar * 10 / 100;
akhir = bayar - diskon;
cout << endl << "selamat anda mendapatkan diskon
10%" <<endl;
}
}
if
(bayar <200000) {
if
(bayar % 200 == 0){
diskon = bayar * 15 / 100;
akhir = bayar - diskon;
cout<<endl<<"selamat
anda mendapatkan diskon 15%"<<endl;
}
else {
akhir
= bayar;
cout
<< "\nSayang sekali tidak ada diskon" << endl;
}
}
cout<<endl<<"jadi total pembayarannya =
"<<akhir<<endl;;
{
int jawab;
cout<<"\n";
cout<<"kembali ke
total pembayaran? \n";
cout<<"1. Ya
\n";
cout<<"2. Tidak /
Exit \n";
cout<<"Pilih
(nomor) : ";
cin>>jawab;
if (jawab==1)
goto menu;
else if(jawab==2)
goto exit1;
else
cout<<"\nData
yang anda masukkan tidak valid"<<"\n"<<"Secara
otomatis akan berhenti";
goto exit;
}
exit1:
{
cout << "\n
Terima Kasih " << endl;
cout << " By :
Muhammad Oemar Abdillah " << endl;
{
return 0;
}
}
exit:
{
cout<<endl<<endl;
{
return 0;
}
}
}
10.
#include
<iostream>
using namespace std;
int main () {
int bil1, bil2;
cout <<"Bilangan 1\t : ";
cin >> bil1;
if (bil1%2 == 0 ) {
cout
<<"Bilangan 1 Genap"<< endl;
}
else
if (bil1 %2 != 0) {
cout
<<"Bilangan 1 Ganjil"<< endl;
}
cout <<"Bilangan 2\t : ";
cin >> bil2;
if (bil2%2 == 0 ) {
cout
<<"Bilangan 2 Genap"<< endl;
}
else
if (bil2 %2 != 0) {
cout
<<"Bilangan 2 Ganjil"<< endl;
}
if
(bil1 > bil2) {
cout
<<"Bilangan 1 lebih besar dari Bilangan 2"<< endl;
}
else
if (bil1 < bil2) {
cout
<<"Bilangan 1 lebih kecil dari bilangan 2"<< endl;
}
}
Comments
Post a Comment