`int a = int.Parse("123") + int.Parse("456");`

Of course you would use variables inside

`TryParse `

instead of constant strings.
See more:

hiii,

how can i do my project?

note: we dont use biginteger class also

we dont use arithmetic operatiors

how can i do my project?

```
string str1="4567995244...4457";
string str2="1458795568...85498";
str1+str2; // addition
str1-str2; // differance
str1*str2; // multiplication
str1/str2; // division
```

note: we dont use biginteger class also

we dont use arithmetic operatiors

Comments

If I understood your question correctly, you first have to change the data type to something you can use in calculation. For example:

Of course you would use variables inside

`int a = int.Parse("123") + int.Parse("456");`

Of course you would use variables inside

`TryParse `

instead of constant strings.Comments

Parse is better, because this API name correctly tell us what really happens, unlike "Convert". My 5.

—SA

—SA

That's true, thanks :)

If BigInteger is not good enough, look around here: http://www.codeplex.com/Wikipage?ProjectName=sine[^]

Comments

Interesting, my 5. However, OP's idea about not using BigInteger is not motivated; most likely, this is just a mistake. As a rule of thumb, OP's "I want" or "I don't want" cannot be taken seriously.

—SA

—SA

Probably. But most likely the OP was told to implement these basic operation as pure symbol/string manipulation.

Agree...

—SA

—SA

Hi,

Try this:

[EDIT]

I've read your comment. So, this is my edit.

I think there's no other option then using a

Hope this helps.

Try this:

```
string str1="4567995244...4457";
string str2="1458795568...85498";
decimal d1 = Convert.ToDecimal(str1);
decimal d2 = Convert.ToDecimal(str2);
decimal addition = d1+d2; // addition
decimal difference = d1-d2; // difference
decimal multiplication = d1*d2; // multiplication
decimal division = d1/d2; // division
```

[EDIT]

I've read your comment. So, this is my edit.

Orhss wrote:note: we dont use biginteger class also

I think there's no other option then using a

`BigInteger`

. Add a reference to System.Numerics.dll, add `using System.Numerics;`

to the top of your code file, and then use this code:```
BigInteger b1 = BigInteger.Parse(str1);
BigInteger b2 = BigInteger.Parse(str2);
BigInteger addition = b1 + b2;
BigInteger difference = b1 - b2;
BigInteger multiplication = b1 * b2;
BigInteger division = b1 / b2;
```

Hope this helps.

v2

Comments

+5

Thank you!

your solution is true but we should use very long string

ex:

12345678901234567891234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

like this...

thanks

ex:

12345678901234567891234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

like this...

thanks

I updated my answer.

right,but we should not use biginteger class and arithmetic operations

Why not?

our project

I don't understand.

i think so we do with multi arrays

So?

Why should you not use BigInteger in your project?

Why should you not use BigInteger in your project?

Gibberish. Unless you clearly explain why not BigInteger, no one will take is seriously.

—SA

—SA

using System;

class Program

{

static void Main()

{

string number1 = "12345678978945612378945612378945612378945664563214722155278954";

string number2 = "7894561233214569877896541233214569874563258966558632889625";

string number3 = Add(number1, number2);

Console.WriteLine(number3);

Console.ReadKey();

}

static string Add(string n1, string n2)

{

int len1 = n1.Length;

int len2 = n2.Length;

int max = Math.Max(len1, len2);

int[] ia1 = new int[max];

int[] ia2 = new int[max];

int[] ia3 = new int[max + 1]; // allow for carry forward

for(int i = max - len1; i < max; i++) ia1[i] = n1[i + len1 - max] - 48;

for(int i = max - len2; i < max; i++) ia2[i] = n2[i + len2 - max] - 48;

int sum = 0;

int carry = 0;

for(int i = max - 1; i >= 0; i--)

{

sum = ia1[i] + ia2[i] + carry;

ia3[i + 1] = sum % 10;

carry = sum / 10;

}

if (carry == 1) ia3[0] = 1;

char[] c3 = new char[max + 1];

for(int i = 0; i < max + 1; i++) c3[i] = (char)(ia3[i] + 48);

return new string(c3).TrimStart('0');

}

}

class Program

{

static void Main()

{

string number1 = "12345678978945612378945612378945612378945664563214722155278954";

string number2 = "7894561233214569877896541233214569874563258966558632889625";

string number3 = Add(number1, number2);

Console.WriteLine(number3);

Console.ReadKey();

}

static string Add(string n1, string n2)

{

int len1 = n1.Length;

int len2 = n2.Length;

int max = Math.Max(len1, len2);

int[] ia1 = new int[max];

int[] ia2 = new int[max];

int[] ia3 = new int[max + 1]; // allow for carry forward

for(int i = max - len1; i < max; i++) ia1[i] = n1[i + len1 - max] - 48;

for(int i = max - len2; i < max; i++) ia2[i] = n2[i + len2 - max] - 48;

int sum = 0;

int carry = 0;

for(int i = max - 1; i >= 0; i--)

{

sum = ia1[i] + ia2[i] + carry;

ia3[i + 1] = sum % 10;

carry = sum / 10;

}

if (carry == 1) ia3[0] = 1;

char[] c3 = new char[max + 1];

for(int i = 0; i < max + 1; i++) c3[i] = (char)(ia3[i] + 48);

return new string(c3).TrimStart('0');

}

}

like this

but we dont use arithmetic operators

but we dont use arithmetic operators

im a student our lecturer wants to without biginteger class

I understand. In that case, have a look at Solution 3.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada
+1 416-849-8900 x 100

—SA