Kasus 5.4

Hai.. ..
Aku langsung saja ya.

Soalnya buatlah fungsi perkalian 2 bilangan bulat dengan menggunakan operator penjumlahan.




#include <iostream>
#include <math.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int kali(int a, int b) {
int i, hasil=0;
for(i=1; i<=abs(b);i++)
hasil+=a;
if (b<0)
return(-hasil);
else
return(hasil);
}
main(){
int a,b;
cout<<"masukkan nilai : "; cin>>a;
cout<<"nilai yang akan dikali : "; cin>>b;
cout<<"Nilai "<<a<<" x "<<b<<" = "<<kali(a,b);
return 0;
}

Ya begitulah , semoga bermanfaat..
Share on Google Plus

About Luthfi

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 komentar:

Posting Komentar