Program mencetaklah bilangan bulat terbalik secara iteratif maupun rekursif



#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 main(int argc, char** argv) {
    int a,b,i,jumlah=0;
    cout<<"Menghitung Perkalian dengan Penjumlahan"<<endl;
    cout<<"Masukan Nilai pertama = ";cin>>a;
    cout<<"Masukan Nilai Kedua   = ";cin>>b;
    if (a>0 && a<0 || b>0){
    for(i=1;i<=b;i++)
        jumlah+=a;
        cout<<a<<"x"<<b<<"="<<jumlah;
    }else if(b<0 && a<0){
        for(i=0;i>a;i--)
        jumlah-=b;
        cout<<a<<"x"<<b<<"="<<jumlah;          
    }else{
        for(i=1;i<=a;i++)
        jumlah+=b;
        cout<<a<<"x"<<b<<"="<<jumlah;
    }
    return 0;
}


Comments