Breaking News
Loading...
Selasa, 22 Maret 2016

Tugas 4.8

Menghitung Perkalian dengan Penjumlahan :

Dev C++:

#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;
}

Ini Hasilnya :





0 komentar:

Posting Komentar

Copyright © 2014 My Blog My Adventure All Right Reserved