Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- class SumBigNumbers
- {
- static void Main(string[] args)
- {
- string firstWord = Console.ReadLine();
- string secondWord = Console.ReadLine();
- Sum(firstWord, secondWord);
- }
- static void Sum(string firstWord, string secondWord)
- {
- StringBuilder builder = new StringBuilder();
- int maxLenth = Math.Max(firstWord.Length, secondWord.Length);
- int remainder = 0;
- firstWord = firstWord.PadLeft(maxLenth, '0');
- secondWord = secondWord.PadLeft(maxLenth, '0');
- for (int index = maxLenth - 1; index >= 0; index--)
- {
- int sum = firstWord[index] - 48 + secondWord[index] - 48 + remainder;
- builder.Insert(0, sum % 10);
- remainder = sum / 10;
- if (index == 0)
- {
- builder.Insert(0, remainder);
- }
- }
- string result = string.Join("", builder.ToString().TrimStart('0'));
- Console.WriteLine(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment