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();
} |
#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();
}
Editorial Team
We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.
It will not work
1.If a is -ve
2.b is -ve
#include
#include
{
clrscr();
int a,b,c;
cout<>a>>b;
c=a*b;
cout<<"The answer is: "<<c;
getch();
}
Hi,
just update the For loop condition
#include
#include
void main ()
{
int a,b,i,temp=0;
clrscr();
cout<>a>>b;
for(i=1;i<b;i++)
{
temp=temp+a;
}
cout<<endl<<"Result are:: "<<temp;
getch();
}
also
for(i=0;i<=a;i+)
{
for(j=0;j<=b;j++)
{
count++;
}
}
printf("%d",count);
while loop?
I really like reading through a post that will make people think.
Also, many thanks for allowing for me to comment!