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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
jnmsyPosted Apr 23, 2012, 7:24 AM
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
lakshmipathi vemulaPosted Apr 23, 2012, 7:18 AM
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;
}
}
}
}
Kunal VaishyaPosted Apr 21, 2012, 11:29 AM
{
Double iResult ;
iResult =0;
if (A == 0 || B == 0)
{
iResult = 0;
}
else
{
for (int i = 1; i <= B; i++)
{
iResult = iResult + A;
}
}
return iResult;
}
Satyapriya NayakPosted Apr 21, 2012, 8:32 AM
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
VulpesPosted Apr 21, 2012, 8:16 AM