Venciity

[Jumpstart C#] homework loops - result

Jan 24th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. /*Напишете програма която приема вход от клавиатурата две положителни числа m и n
  2.  * и отпечатва цялата част и остатъка при делението на m със n.
  3.  * Използвайте операция изваждане и цикъл при решаването на задачата
  4.  * (не използвайте оператори / и %)     */
  5.  
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11.  
  12. namespace _4.EX
  13. {
  14.     class Program
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             Console.Write("m = ");
  19.             int dividend = Int32.Parse(Console.ReadLine()); //dividend = делимо
  20.  
  21.  
  22.             Console.Write("n = ");
  23.             int divisior = Int32.Parse(Console.ReadLine()); //divisior = делител
  24.  
  25.             int quotient = 0;  // quotient = частно
  26.  
  27.             while (dividend >= divisior) // докато делимото е  >= на делителят прави :
  28.             {
  29.                 dividend -= divisior;    // делимо = делимо - делител
  30.                 quotient++;              // увеличи quitient с единица
  31.             }
  32.  
  33.             Console.WriteLine("quotient: {0}", quotient);
  34.             Console.WriteLine("remainder: {0}", dividend);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment