ret_0

c# prac6 var 18

Oct 24th, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. // 1
  2. using System;
  3.                    
  4. public class Program
  5. {
  6.    
  7.     static int exp(int i, int n)
  8.     {
  9.         if(i == n)
  10.             return n;
  11.         return i + exp(++i, n);
  12.     }
  13.    
  14.     public static void Main()
  15.     {
  16.         Console.Write("count sum from 1 to m + from 1 to 2k\nEnter m = ");
  17.         int m, k, a, b;
  18.         m = int.Parse(Console.ReadLine());
  19.         Console.Write("Enter k = ");
  20.         k = int.Parse(Console.ReadLine());
  21.         a = exp(1, m);
  22.         b = exp(1, 2*k);
  23.         Console.Write("{0} + {1} = {2}", a, b, (a + b));
  24.     }
  25. }
  26.  
  27.  
  28. // 2
  29. using System;
  30.                    
  31. public class Program
  32. {
  33.    
  34.     static void disp(int n)
  35.     {
  36.         if(n == 0)
  37.             return;
  38.         disp(--n);
  39.         Console.Write((++n) + " ");
  40.     }
  41.    
  42.     public static void Main()
  43.     {
  44.         Console.Write("natural numbers 1 .. N\nEnter N = ");
  45.         int n = int.Parse(Console.ReadLine());
  46.         disp(n);
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment