Guest User

Rekurencja

a guest
Nov 2nd, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Zad._3
  8. {
  9.     class Program
  10.     {
  11.         static void parzystość(int n)
  12.         {
  13.             if (n % 2 == 0)
  14.             {
  15.                 Console.WriteLine(n);
  16.             }
  17.             if (n==0)
  18.             {
  19.                
  20.             }
  21.             else
  22.             {
  23.                 if (n%2==0)
  24.                 { parzystość(n - 2); }
  25.                 else { parzystość(n - 1); }
  26.             }
  27.         }
  28.        
  29.         static void Main(string[] args)
  30.         {
  31.             int n;
  32.             Console.WriteLine("Podaj n");
  33.             n = Convert.ToInt32(Console.ReadLine());
  34.             parzystość(n);
  35.             Console.ReadKey();
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment