Advertisement
vencinachev

Exam Preparation

Oct 3rd, 2019
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Exam01
  5. {
  6.     class Program
  7.     {
  8.         public static int mult(int m, int n)
  9.         {
  10.             if (n == 1)
  11.             {
  12.                 return m;
  13.             }
  14.             return mult(m, n - 1) + m;
  15.         }
  16.  
  17.         public static int mult2(int m, int n)
  18.         {
  19.             if (n == 1)
  20.             {
  21.                 return m;
  22.             }
  23.             else if (n > 1)
  24.             {
  25.                 return mult2(m, n - 1) + m;
  26.             }
  27.             return mult2(m, n + 1) - m;
  28.         }
  29.  
  30.         static void Main(string[] args)
  31.         {
  32.             // Exam 01:
  33.             /*int days = int.Parse(Console.ReadLine());
  34.             int[] cards = { 100, 20 };
  35.             int money = days * 20;
  36.             int count = 0;
  37.             for (int i = 0; i < cards.Length; i++)
  38.             {
  39.                 while (money - cards[i] >= 0)
  40.                 {
  41.                     money -= cards[i];
  42.                     count++;
  43.                 }
  44.                 if (money == 0)
  45.                 {
  46.                     break;
  47.                 }
  48.             }
  49.             Console.WriteLine(count);*/
  50.  
  51.             // Exam02:
  52.             int[] numbers = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray();
  53.             int result = mult2(numbers[0], numbers[1]);
  54.             Console.WriteLine(result);
  55.  
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement