Advertisement
Guest User

Fibonacci Assigning

a guest
Dec 2nd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 KB | None | 0 0
  1.         static void Main(string[] args)
  2.         {
  3.             int x, y;
  4.  
  5.             // Input 'X' & 'Y':
  6.             Console.WriteLine("Enter a value for 'X' (Range of 1-99999):");
  7.             x = int.Parse(Console.ReadLine());
  8.             Console.WriteLine("Enter a value for 'Y' (Range of 1-99999):");
  9.             y = int.Parse(Console.ReadLine());
  10.  
  11.             // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  12.  
  13.             // Getting the length of the fiboArray:
  14.             int first = 1, second = 1, temp, counter = 0, i = 0;
  15.  
  16.             while (second < 99999)
  17.             {
  18.                 temp = second;
  19.                 second += first;
  20.                 first = temp;
  21.                 counter++;
  22.             }
  23.  
  24.             // Inputing the fiboArray values:
  25.             int[] fiboArray = new int[counter];
  26.             first = 1;
  27.             second = 1;
  28.  
  29.             while (second < 99999)
  30.             {
  31.                 fiboArray[i] = second;
  32.                 temp = second;
  33.                 second += first;
  34.                 first = temp;
  35.                 i++;
  36.             }
  37.  
  38.             // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39.  
  40.             // Assign Values to the grid:
  41.             int[,] grid = new int[x + 8, y + 9];
  42.             counter = 0;
  43.             int f=0;
  44.             for (i = 0; i < x + 8; i++)
  45.             {
  46.                 for (int j = 0; j < y + 9; j++)
  47.                 {
  48.                     if (i > j)
  49.                     {
  50.                         while (j > fiboArray[f])
  51.                         {
  52.                             f++;
  53.                         }
  54.  
  55.                         while (i > fiboArray[f])
  56.                         {
  57.                             counter++;
  58.                             f++;
  59.                         }
  60.                     }
  61.                     else
  62.                     {
  63.                         while (i > fiboArray[f])
  64.                         {
  65.                             f++;
  66.                         }
  67.  
  68.                         while (j > fiboArray[f])
  69.                         {
  70.                             counter++;
  71.                             f++;
  72.                         }
  73.                     }
  74.  
  75.                     grid[i, j] = counter;
  76.                     counter = 0;
  77.                     f = 0;
  78.                 }
  79.             }
  80.  
  81.             // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82.  
  83.             // Print the grid:
  84.             for (i = 0; i < x + 8; i++)
  85.             {
  86.                 for (int j = 0; j < y + 9; j++)
  87.                 {
  88.                     Console.Write(grid[i, j]);
  89.                 }
  90.                 Console.WriteLine("");
  91.             }
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement