Multiplication of two numbers by addition method
This below mentioned example shows how to add 2 numbers by addition method.
Code
#include "stdafx.h"
#include "iostream"
#include "conio.h"
using namespace std;
int main()
{
int num1=0;
int num2=0;
int result=0;
cout<<"ENTER FIRST NUMBER > ";
cin>>num1;
cout<<"ENTER SECOND NUMBER > ";
cin>>num2;
result=num1;
for(int i=1;i<num2;i++)
result+=num1;
cout<<"RESULT OF SIMPLE MULTIPLICATION > "<<num1*num2<<endl;
cout<<"RESULT OF MULTIPLICATION BY ADDITION METHOD > "<<result<<endl;
_getche();
return 0;
}
Output
ENTER FIRST NUMBER > 6
ENTER SECOND NUMBER > 4
RESULT OF SIMPLE MULTIPLICATION > 24
RESULT OF MULTIPLICATION BY ADDITION METHOD > 24
0 comments:
Post a Comment