skip to main |
skip to sidebar
/*PROGRAM DISCOUNT DENGAN FUNGSI*/
#include<conio.h>
#include<iostream.h>
#pragma argsused
double price;
double discount(double rp)
{
double disc=rp*20/100;
price=rp-disc;
cout<<"Discount : Rp "<<disc<<endl;
cout<<"Harga setelah discount : Rp "<<price<<endl;
}
double sisauang(double pay)
{
double sisa=pay-price;
cout<<"Sisa uang : Rp "<<sisa<<endl;
}
int main()
{
double rp,pay;
cout<<"PROGRAM DISKON"<<endl;
cout<<"=============="<<endl;
cout<<endl;
cout<<"***********************************************"<<endl;
cout<<"*Diskon 20% untuk pembelian Rp100.000 keatas !*"<<endl;
cout<<"***********************************************"<<endl;
cout<<endl;
cout<<"-----------------------------------------------"<<endl;
cout<<"Masukkan harga barang : Rp "; cin>>rp;
cout<<"Jumlah nominal yang dibayar : Rp "; cin>>pay;
cout<<endl;
cout<<"-----------------------------------------------"<<endl;
cout<<endl;
if(pay>=rp)
{
if(rp>=100000)
{
discount(rp);
}
else
{
cout<<"Discount : Rp 0"<<endl;
price=rp;
}
sisauang(pay);
}
else
{
cout<<"MAAF UANG ANDA TIDAK CUKUP !"<<endl;
}
cout<<endl;
cout<<"***"<<endl;
getch();
}
/*FUNGSI TUKAR BILANGAN*/
#pragma argsused
#include <conio.h>
#include <iostream.h>
int tukar(int &bil1,int &bil2)
{
cout<<"Nilai Awal : "<<bil1<<" "<<bil2<<endl;
int temp;
temp=bil1;
bil1=bil2;
bil2=temp;
cout<<"Setelah Ditukar : "<<bil1<<" "<<bil2<<endl;
}
int main()
{
int nil1,nil2;
cout<<"PROGRAM TUKAR NILAI"<<endl;
cout<<"==================="<<endl;
cout<<endl;
cout<<"Nilai 1 : "; cin>>nil1;
cout<<endl;
cout<<"Nilai 2 : "; cin>>nil2;
cout<<endl;
cout<<endl;
cout<<endl;
tukar(nil1,nil2);
cout<<endl;
getch();
}
#pragma argused
#include<conio.h>
#include<iostream.h>
int main()
{
int data[20];
int i,x,jum,mid,rata,xyz;
cout<<"PROGRAM PENJUMLAHAN DATA"<<endl;
cout<<"------------------------"<<endl;
cout<<endl;
cout<<"Masukkan Jumlah Data (Ganjil 1-20) : ";
cin>>x;
for(i=1;i<=x;i++)
{
cout<<"Data ke-"<<i<<" : " ;
cin>> data[i];
}
cout<<endl;
cout<<"Data yang tadi dimasukkan : ";
jum=0;
for(i=1;i<=x;i++)
{
cout<<data[i]<<" ";
jum=jum+data[i];
}
cout<<endl;
cout<<endl;
cout<<"Total Penjumlahan Data : "<<jum<<" "<<endl;
rata=jum/x;
cout<<"Rata-rata Data : "<<rata<<endl;
mid=(x+1)/2;
cout<<"Data tengah (Data ke-"<<mid<<") : "<<data[mid]<<endl;
xyz=data[1]+data[x];
cout<<"Data awal + Data akhir : "<<xyz<<endl;
getch();
}
#pragma argused
#include<conio.h>
#include<iostream.h>
int main()
{
int i,x,jum5,jum7,sisa;
cout<<"BILANGAN YANG HABIS DIBAGI 7 DAN 5"<<endl;
cout<<"----------------------------------"<<endl;
cout<<endl;
cout<<"Masukkan Batas Deret Bilangan : ";
cin>>x;
cout<<endl;
cout<<"Deret Bilangan : ";
for(i=1;i<=x;i++)
{
cout<<i<<" ";
}
cout<<endl;
cout<<"Bilangan yang habis dibagi 5 : ";
jum5=0;
for(i=1;i<=x;i++)
{
sisa = i%5;
if (sisa==0) cout<<i<<" ";
if (sisa==0) jum5=jum5+i;
}
cout<<endl;
cout<<"Bilangan yang habis dibagi 7 : ";
jum7=0;
for(i=1;i<=x;i++)
{
sisa = i%7;
if (sisa==0) cout<<i<<" ";
if (sisa==0) jum7=jum7+i;
}
cout<<endl;
cout<<endl;
cout<<"Jumlah yang habis dibagi 5 : "<<jum5<<endl;
cout<<"Jumlah yang habis dibagi 7 : "<<jum7<<endl;
cout<<"Total semuanya : "<<jum5+jum7<<endl;
getch();
}