Friday, February 12, 2016

MembuaT program C++ dengan Prosedur dan Fungsi

PROGRAM FOR

#include <iostream>
#include<conio.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main() {
int c;

cout <<"<<<<<<<<<<<<<<<program for>>>>>>>>>>>>>>>.\n\n\n";

for (c=0; c<10; c++)
{cout<<"\tresi ok\n";
}


                return 0;
}


PROGRAM FUNGSI

#include <iostream>

using namespace std;

int min(int a, int b);

int main()
{
               
                cout<<"#PROGRAM FUNGSI\n\n\n\n";
                int x=1;
                int y=100;
                int maksimal;
               
                maksimal = max(x,y);
               
                cout<<" \tnilai mINIMAL adalah : "<<maksimal<<endl;
               
                return 0;
}

int max(int a, int b)
{
                int result;
                if(a<b)
               
                result=a;
                else
                result=b;
               
                return result;
}


PROGRAM PROSEDUR

#include<iostream>
using namespace std;

void volume_Kubus()
{
 
double p,l,t;
cout<<"#PROGRAM PROSEDUR\n\n\n";
cout<<"-=-=-=-=-=-=-=-=-=-=-=-=-=Volume BALOK=-=-=-=-=-=-=-=-=-=-=-=-=\n"<<endl;
cout<<"Masukkan panjang : ";
cin>>p;
cout<<"Masukkan lebar : ";
cin>>l;
cout<<"Masukkan tinggi : ";
cin>>t;
cout<<"Volume BALOK : "<<p*l*t<<endl;
}

void volume_tabung()
{
double r,t;

cout<<"\n-=-=-=-=-=-=-=-=-=-=-=-=-=Volume tabung=-=-=-=-=-=-=-=-=-=-=-=-=\n"<<endl;
cout<<"Masukkan jari-jari : ";
cin>>r;
cout<<"Masukkan tinggi : ";
cin>>t;
cout<<"Volume tabung = "<<3.14*r*r*t<<endl;
}


int main()
{
volume_Kubus();
volume_tabung();

return 0;
}

PROGRAM DO WHILE

#include <iostream>
#include<conio.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main() {
               
                int i=0;
cout<<" #program do while\n\n";           

do
{
               
                cout<<"\tnilai i : "<<i<<endl;
                i=i+1;

}while (i<=10);
}


PROGRAM WHILE

#include <iostream>
#include<conio.h>

using namespace std;

int main() {
               
 cout<<" #PROGRAM WHILE\n\n\n\n\n";

   int a = 1;

   while( a<3 )
   {
       cout << "\n a: " << a << endl;
       a++;
   }

   return 0;
}


No comments:

Post a Comment