Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Add Two String Numbers which may be large - Author MC
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Globalization; namespace Rextester { public class Program { public static void Main(string[] args) { String s1 = "000123456"; String s2 = "78901234512345"; Int64 tempResult = 0; Int64 remainder = 0; int strLen1 = 0; int strLen2 = 0; string sNum1 = null; string sNum2 = null; string result = ""; Int64 nNum1 = 0; Int64 nNum2 = 0; // while more chunks while (s1.Length > 0 || s2.Length > 0) { tempResult = 0; strLen1 = s1.Length < 10 ? s1.Length: 10; strLen2 = s2.Length < 10 ? s2.Length: 10; sNum1 = s1.Substring(s1.Length-strLen1, strLen1); sNum2 = s2.Substring(s2.Length-strLen2, strLen2); Console.Write("NUM1:"); Console.WriteLine(sNum1); Console.Write("NUM2:"); Console.WriteLine(sNum2); s1 = s1.Substring(0, s1.Length-strLen1); s2 = s2.Substring(0, s2.Length-strLen2); nNum1 = 0; nNum2 =0; try { if (sNum1.Length > 0) nNum1 = Int64.Parse( sNum1, NumberStyles.Number); if (sNum2.Length > 0) nNum2 = Int64.Parse( sNum2, NumberStyles.Number); } catch (FormatException fe) { Console.WriteLine(fe.Message); if (fe.InnerException != null) Console.WriteLine(fe.InnerException.Message); throw new Exception("Part of Number is Invalid :" + (!String.IsNullOrEmpty(sNum1) ? sNum1 : "null")); } tempResult = remainder; // convert addition to string Console.Write("nNum1:"); Console.WriteLine(nNum1.ToString()); Console.Write("nNum2:"); Console.WriteLine(nNum2.ToString()); tempResult = tempResult + nNum1; tempResult = tempResult + nNum2; remainder = tempResult > Int32.MaxValue ? tempResult-Int32.MaxValue : 0; if (tempResult > Int32.MaxValue) tempResult = Int32.MaxValue; Console.Write("TempResult:"); Console.WriteLine(tempResult.ToString()); result = tempResult.ToString() + result; } Console.Write(" RESULT : " ); Console.WriteLine(result); } } }
run
|
edit
|
history
|
help
0
Hello world
Fibbonachi number by LINQ expression
ASXs
Ty
Dio
Find the integers which squares sum gives the prime numbers of the form (4k + 1).
SimpleHelloworldProgram
Main5.1
CodeAdvent
Better Random number blocks