Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TwoNumbersDigitSums
- {
- class Program
- {
- static void Main(string[] args)
- {
- int num1Total = 0, num2Total = 0, num1=0, num2=0;
- bool wrongInput = true, num1NotOver = true, num2NotOver = true;
- while (wrongInput)
- {
- num1 = int.Parse(Console.ReadLine());
- num2 = int.Parse(Console.ReadLine());
- if (num2 > num1)
- wrongInput = false;
- else
- Console.WriteLine("ERROR! Second number must be bigger than first!");
- }
- int num1ForCalcs = num1;
- int num2ForCalcs = num2;
- while (num1NotOver)
- {
- num1Total += num1ForCalcs % 10;
- num1ForCalcs /= 10;
- if (num1ForCalcs == 0)
- num1NotOver=false;
- }
- while (num2NotOver)
- {
- num2Total += num2ForCalcs % 10;
- num2ForCalcs /= 10;
- if (num2ForCalcs == 0)
- num2NotOver = false;
- }
- Console.WriteLine("First number digits sum: {0}. Second number digits sum: {1}", num1Total, num2Total);
- if (num1Total > num2Total)
- Console.WriteLine(num1 +"'s digits sum is greater.");
- else if (num1Total < num2Total)
- Console.WriteLine(num2 +"'s digits sum is greater.");
- else
- Console.WriteLine("Numbers' digits' sum is equal!");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement