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(); } |












It will not work
1.If a is -ve
2.b is -ve
inefficient program
how include negative numbers?
how include negative numbers?
how include negative numbers?
THNAKS
thank u sommuch
how include negative numbers?
// 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;
}
// 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;
}
thanks
good
Thanks
#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!