Contoh Program fungsi pada C++


#include <iostream.h>
int fungsi_tambah(int x, int y)
{
int z;
z = x + y;
x+=2;
y+=5;
return z;
}
main()
{
int a, b, c;
a = 4;
b = 6;
c = fungsi_tambah(a, b);
cout<<"Nilai A = "<<a;
cout<<"\nNilai B = "<<b;
cout<<"\nHasil Proses Tambah = "<<c;

}






#include <iostream.h>
#include <conio.h>
void main()
{
float n, total, rata2;
total = 0;

for(int i=0; i<10; i++)
{
 cout<<"Masukkan nilai ke "<<(i+1)<<" : ";
cin>>n;
total = total + n;
}
rata2 = total / 10;
cout<<"Total = "<<total<<endl;
cout<<"Rata2 = "<<rata2<<endl;
getch();
}

No comments:

Post a Comment

KOMENTAR ANDA AKAN SANGAT KAMI HARGAI
MAKA BERKOMENTARLAH DEMI KEMAJUAN BLOG INI