C++ program to multiply two numbers without using multiplication operator

Sunday, April 4th, 2010

Write a c++ program to multiply two numbers without using multiplication operator.

#include<iostream.h>
#include<conio.h>
void main ()
{
int a,b,i,temp=0;
clrscr();
cout<<"Enter Two numbers for multiplication";
cin>>a>>b;
for(i=1;i<=b;i++)
{
temp=temp+a;
}
cout<<endl<<"Result are:: "<<temp;
getch();
}
Avatar Image

Author Name :
Ranjith

Total : 11 Comments


11 Responses to C++ program to multiply two numbers without using multiplication operator

  1. Swapna

    It will not work
    1.If a is -ve
    2.b is -ve

  2. harpreet

    inefficient program :P

  3. sasi

    how include negative numbers?

  4. sasi

    how include negative numbers?

  5. sasi

    how include negative numbers?

  6. MONA

    THNAKS

  7. jaffar

    thank u sommuch

  8. kavitha

    how include negative numbers?

  9. XZz_Yassin

    // Multiplication.cpp : By Mu’men Yassin (XZz_Yassin)

    #include
    using namespace std;

    int multiplication(int a,int b){
    int total=0,c;
    if(a>=0){
    for (int c=0;c=a+1;c–){
    if(b>=0){
    total-=b;
    }
    else{
    total-=b;
    total=abs(total);
    }

    }
    }
    return total;
    }

    int main()
    {
    while(true){
    int x,y;
    char check;
    cout <>x;
    cout <>y;
    cout<<endl<<multiplication(x,y)<<endl;
    cout<>check;
    cout<<endl;
    if(check=='Y' || check=='y'){
    continue;
    }
    else{ //it's never mind if the user entered N or n or else
    break;
    }
    }
    cout << "Thnx for using my product, XZz_Yassin 2012\n";
    system ("PAUSE");
    return 0;
    }

  10. XZz_Yassin

    // Multiplication.cpp : By Mu'men Yassin (XZz_Yassin)

    #include
    using namespace std;

    int multiplication(int a,int b){
    int total=0,c;
    if(a>=0){
    for (int c=0;c=a+1;c--){
    if(b>=0){
    total-=b;
    }
    else{
    total-=b;
    total=abs(total);
    }

    }
    }
    return total;
    }

    int main()
    {
    while(true){
    int x,y;
    char check;
    cout <>x;
    cout <>y;
    cout<<endl<<multiplication(x,y)<<endl;
    cout<>check;
    cout<<endl;
    if(check=='Y' || check=='y'){
    continue;
    }
    else{ //it's never mind if the user entered N or n or else
    break;
    }
    }
    cout << "Thnx for using my product, XZz_Yassin 2012\n";
    system ("PAUSE");
    return 0;
    }

  11. afsar mumtaz

    thanks

Leave a Reply

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup