Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1
- using System;
- public class Program
- {
- static int exp(int i, int n)
- {
- if(i == n)
- return n;
- return i + exp(++i, n);
- }
- public static void Main()
- {
- Console.Write("count sum from 1 to m + from 1 to 2k\nEnter m = ");
- int m, k, a, b;
- m = int.Parse(Console.ReadLine());
- Console.Write("Enter k = ");
- k = int.Parse(Console.ReadLine());
- a = exp(1, m);
- b = exp(1, 2*k);
- Console.Write("{0} + {1} = {2}", a, b, (a + b));
- }
- }
- // 2
- using System;
- public class Program
- {
- static void disp(int n)
- {
- if(n == 0)
- return;
- disp(--n);
- Console.Write((++n) + " ");
- }
- public static void Main()
- {
- Console.Write("natural numbers 1 .. N\nEnter N = ");
- int n = int.Parse(Console.ReadLine());
- disp(n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment