skip to main |
skip to sidebar
#include <conio.h>
#include <iostream.h>
#pragma argsused
int main()
{
int i,x,f,k,hasil;
cout<<"FAKTORIAL BILANGAN"<<endl;
cout<<"------------------"<<endl;
cout<<endl;
cout<<"Masukkan jumlah faktorial : "; cin>>x;
cout<<endl;
for(i=1;i<=x-1;i++)
{
cout<<i<<"! : ";
hasil=1;
for(f=1;f<=i;f++)
{
k=f;
hasil=hasil*k;
}
cout<<hasil;
cout<<endl;
}
cout<<"--------------------------"<<endl;
cout<<i<<"! : ";
for(i=1;i<=x;i++)
{
cout<<i<<" * ";
}
cout<<endl;
for(i=1;i<=x;i++)
{
hasil=1;
for(f=1;f<=i;f++)
{
k=f;
hasil=hasil*k;
}
}
i=x;
cout<<i<<"! : "<<hasil;
getch();
}
#include <conio.h>
#include <iostream.h>
#pragma argsused
int main()
{
int n0,n1,n2,i,bil;
cout<<"DERET BILANGAN FIBONACCI"<<endl;
cout<<"------------------------"<<endl;
cout<<endl;
cout<<"Masukkan batas bilangan : ";
cin>>bil;
cout<<endl;
cout<<"Deret Bilangan : ";
for(i=1;i<=bil;i++)
{
cout<<i<<" ";
}
cout<<endl;
cout<<"Deret Fibonacci : ";
n0=0;
n1=1;
for(i=1;i<=bil;i++)
{
n2=n0+n1;
cout<<n2<<" ";
n0=n1;
n1=n2;
}
getch();
}
#pragma argsused
#include<iostream.h>
#include<conio.h>
int main()
{
int nilai[20];
int i,x,j,k,temp;
cout<<"Mengurutkan Data Nilai"<<endl;
cout<<"======================"<<endl;
cout<<endl;
cout<<"Masukkan Banyak Input = ";cin>>x;
cout<<"------------------------"<<endl;
for(i=1;i<=x;i++)
{
cout<<"Nilai Ke-"<<i<<" : "; cin>>nilai[i];
}
cout<<endl;
cout<<"----------------------------"<<endl;
cout<<"Input sebelum diurutkan : "<<endl;
for(i=1;i<=x;i++)
{
cout<<nilai[i]<<" ";
}
cout<<endl;
cout<<endl;
for(j=1;j<=x;j++)
{
for(k=j+1;k<=x;k++)
{
if(nilai[j]>nilai[k])
{
temp=nilai[j];
nilai[j]=nilai[k];
nilai[k]=temp;
}
}
}
cout<<"Input setelah diurutkan : "<<endl;
for(i=1;i<=x;i++)
{
cout<<nilai[i]<<" ";
}
getch();
}
/*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();
}