Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 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 ExerciceAlgo
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             while (1== 1)
  14.             {
  15.                 menu();
  16.             }
  17.         }
  18.         public static void menu()
  19.         {
  20.             Console.WriteLine("Chosir nb à tester");
  21.             int nb = 0;
  22.             nb= int.Parse(Console.ReadLine());
  23.             int i = 0;
  24.             while (nb != 1)
  25.             {
  26.                
  27.                 nb= Syracuse(nb);
  28.                 i++;
  29.             }
  30.             Console.WriteLine("Temps de vol : {0}", i);
  31.  
  32.         }
  33.         public static int Syracuse(int nb)
  34.         {
  35.             if (nb > 0)
  36.             {
  37.                 if ((nb%2)==0)
  38.                 {
  39.                     return nb / 2;
  40.                 }
  41.                 else
  42.                 {
  43.                     return nb * 3 + 1;
  44.                 }
  45.             }
  46.             return 0;
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement