TheBulgarianWolf

Comparisson and sums of the bigger numbers

Oct 11th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Numerics;
  4.  
  5. namespace SoftuniExercisesWithVariables
  6. {
  7.     class Program
  8.     {
  9.         static int CalculateSum(int num)
  10.         {
  11.             int tempNum;
  12.             int sum = 0;
  13.             while(num > 0)
  14.             {
  15.                 tempNum = num % 10;
  16.                 num = num / 10;
  17.                 sum += tempNum;
  18.             }
  19.             return sum;
  20.         }
  21.  
  22.         static void Main(string[] args)
  23.         {
  24.             Console.WriteLine("Enter the number of comparissons you are about to make: ");
  25.             int lines = int.Parse(Console.ReadLine());
  26.             List<int> listNums = new List<int>();
  27.             while(lines > 0)
  28.             {
  29.                 string line = Console.ReadLine();
  30.                 string[] numbers = line.Split(" ");
  31.                 int numberOne = int.Parse(numbers[0]);
  32.                 int numberTwo = int.Parse(numbers[1]);
  33.                 if(numberOne > numberTwo)
  34.                 {
  35.                     listNums.Add(CalculateSum(numberOne));
  36.                 }
  37.                 else
  38.                 {
  39.                     listNums.Add(CalculateSum(numberTwo));
  40.                 }
  41.                 lines--;
  42.             }
  43.             foreach(int a in listNums)
  44.             {
  45.                 Console.WriteLine(a);
  46.             }
  47.            
  48.  
  49.         }
  50.     }
  51. }
Add Comment
Please, Sign In to add comment