Kasus 4.8

Pertanyaan : 
Hitunglah axb dengan metode penjumlahan.


Jawab:
 #include <iostream>
#include <string>
#include <math.h>
#include <cstdlib>

using namespace std;
int main(){
   int hasil;
   int i;
   int b;
   int a;

   i = 1;
   hasil = 0;
   cout << "Masukkan bilangan yang akan di kalikan = ";
   cin >> a;
   cout << "Akan dikalikan dengan = ";
   cin >> b;
 
   while (!(i>(abs(b)))){
      hasil = hasil + a;a
      i =i+1;
   }
   if (b<0){
      cout << a << " x " << b << " = -" << hasil << endl;
   }
   else{
      cout << a << " x " << b << " = " << hasil << endl;
   }
   return 0;

}



Raptor :


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