Monday, 2 March 2015

C++ Program To Multiply Two Number Without Using Asterisk

Problem:- Write a C++ program to find multiplication of two number without using Asterisk ( * ) Symbol.

Logic:- There are two methods we can use for solving this problem, this is a very important question for interview purpose because we never think about how we can multiply two number without using Asterisk Sign( * ), we just take two value and use the Asterisk Sign( * ) and put between two variables. We will take an example and through an example, we can try to solve the problem and find out the number of the way we can solve the problem.
For solving a mathematical equation there is a VEDIC Math( Old Indian Math ), By the help of VEDIC Math, we can solve large equation is second for an example if you want to check a Number is divisible by 11 or not How you can check in a second and remember number may be very large. For an example, we take a number 161051 is divisible by 11 or not. you can check the demo of VEDIC math, C Program To Check Number Is Divisible By 11 Or Not Using (VEDIC MATH).

Now come to the problem there is two way, So let's take an example suppose we want to multiply 20 and 10 there are two methods you can follow.

Method 1:- Traditional 

You can direct multiple 20 * 10 = 200 this is a very famous  Traditional way for calculating or solving multiplication but here one problem occurring in problem statement specially mention that you can not use an Asterisk Sign(*) So you have to Follow another method.

Method 2:- 

So here we go we know that multiplication is an addition of one number to another number of (First / Second) number of times. Don't get you let's take an example we want to multiply 20 * 10 so we can add 20 into 10 times like 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20 + 20 = 200 or we can add 10 into 20 times answer will be same like 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 + 10 = 200. Here i am using method 2.

Solution:-

#include<iostream>
using namespace std;
int main ()
{
 long a,b,i,temp=0;
 cout<<"Enter Two numbers for multiplication : \n";
 cin>>a>>b;

  for(i=1;i<=b;i++)
 {
  temp=temp+a;
 }
 cout<<endl<<"Result are : "<<temp<<endl;
}

Output:-

Ghanendra Yadav
Ghanendra Yadav

I Am Ghanendra Yadav Owner Of This Website. I Love Programming, Web Developing, Logo Making, Banner And Website designing. Currently I Am Studying In NIT Warangal And Also Working With WSDC( As Web Application Developer ) In NIT Warangal For Any Query Mail Me I Will Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment