hello..
i want multiply two numbers without using * operator?
plz tell me.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
jnmsy19 reputationPosted Apr 23, 2012, 3:24 AM EDT
static int Prod(int a,int b)
{
if (a == 0 || b == 0)
{
return 0;
}
else
{
int sum = 0;
for (int i = 0; i < b; i++)
{
sum += a;
}
return sum;
}
}
For more Information on .NET http://www.bestdotnettraining.com/User/TrainingCourses.aspx
VulpesRank #55 · 29.2K reputationPosted Apr 21, 2012, 4:16 AM EDT
Satyapriya NayakRank #47 · 31.5K reputationPosted Apr 21, 2012, 4:32 AM EDT
Try this...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show(multiply(5, 5).ToString());
}
private int multiply(int a, int b)
{
int result=0, i=0;
while(i != b)
{
result = addition(result,a);
i = addition(i,1);
}
return result;
}
private int addition(int a, int b)
{
int result = 0, carry;
carry = a&b;
if(Convert.ToBoolean(carry))
{
result = a^b;
carry = carry << 1;
result = addition(carry, result);
}
else
{
result = a^b;
}
return result;
}
}
}
Thanks
If this post helps you mark it as answer
Kunal VaishyaRank #990 · 2K reputationPosted Apr 21, 2012, 7:29 AM EDT
{
Double iResult ;
iResult =0;
if (A == 0 || B == 0)
{
iResult = 0;
}
else
{
for (int i = 1; i <= B; i++)
{
iResult = iResult + A;
}
}
return iResult;
}
lakshmipathi vemula20 reputationPosted Apr 23, 2012, 3:18 AM EDT
You can as below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Forums23042012
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Prod(10,10));
}
static int Prod(int a,int b)
{
if (a != 0 && b != 0)
{
int sum = 0;
for (int i = 0; i < b; i++)
{
sum += a;
}
return sum;
}
else
{
return 0;
}
}
}
}