ppt 4 kasus 4.8 Program Menghitung AxB Dengan Metode Penjumlahan.
menghitung A X B dengan metode penjumlahan
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int a,b,hsl=0;
cout<<"program perkalian dengan metode penjumlahan"<<endl;
cout<<"masukan nilai a = "; cin>>a;
cout<<"masukan nilai b = "; cin>>b;
cout<<" "<<a<<" x "<<b<<endl;
for(int i=1;i<=b;i++)
{
cout<<hsl<<"+"<<a<<"=";
hsl=hsl+a;
cout<<hsl<<endl;
}
if(b<0)
cout<<"hasil perkalian = "<<-1*hsl;
else
cout<<"hasil perkalian = "<<hsl;
return 0;
}
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int a,b,hsl=0;
cout<<"program perkalian dengan metode penjumlahan"<<endl;
cout<<"masukan nilai a = "; cin>>a;
cout<<"masukan nilai b = "; cin>>b;
cout<<" "<<a<<" x "<<b<<endl;
for(int i=1;i<=b;i++)
{
cout<<hsl<<"+"<<a<<"=";
hsl=hsl+a;
cout<<hsl<<endl;
}
if(b<0)
cout<<"hasil perkalian = "<<-1*hsl;
else
cout<<"hasil perkalian = "<<hsl;
return 0;
}
raptor
Komentar
Posting Komentar