Wednesday, January 12, 2011

Bab Fungsi

    Program Hitung Luas dan Keliling Lingkaran Menggunakan Fungsi
/**Latihan Bab9  no1**/
/* Created by: Ipah Hanifah */
# include <stdio.h>
# include <conio.h>
# include <iostream.h>
float luas(int r)
{
return(3.14*r*r);
}

float kel(int r)
{
return(3.14*2*r);
}
main()
{
int r;

clrscr();
cout<<"Masukan Nilai Jari : ";cin>>r;
cout<<"\nLuas Lingkaran="<<luas(r);
cout<<"\nKeliling Lingkaran="<<kel(r);
getch();
}
Output









__________________________________________________
    Program Hitung Potongan Harga Belanja
/**Latihan Bab9  no2**/
/* Created by: Ipah Hanifah */
#include<iostream.h>
#include<conio.h>
#include<stdio.h>

int potong(int beli)
{
if(beli> 5000000)
{
    return (0.35*beli);
}
else if((beli>1000000)&&(beli<5000000))
{
     return (0.2*beli);
}
else
    {
   return (0);
   }
}

main()
{
 int beli,harga;
 char diskon;

clrscr();
cout<<"Besar Pembelian Barang = Rp. "; cin>>beli;
cout<<"\nBesar Diskon yg diberikan = Rp. "<<potong(beli)<<endl;
harga=beli-potong(beli);
cout<<"Harga yg harus dibayar    = Rp. "<<harga;

getche();
}

Output:

No comments:

Post a Comment

Goresan pena Si Pengemis ilmu © 2008. Design by :vio Templates Sponsored by: gold bola