Kasus 5.4

Buatlah fungsi perkalian 2 bilangan bulat dengan menggunakan operator 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 i,a,jumlah;
            jumlah=0;
            cout<<"Masukan batas bilangan : ";
            cin>>a;
            cout<<endl;
            for (i=1; i<a; i++){
                        cout<<i<< " + ";
                        jumlah=jumlah+i;
            }
            cout<<a<<" = "<<jumlah+a;
            return 0;
}

 

 

 

Previous
Next Post »
Copyright © 2015 Bettong'rs All Right Reserved
Created by Arlina Design Powered by Blogger