Venciity

[SoftUni C# exam preparation] 02.A-nacci

Apr 9th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. /*condition : https://www.dropbox.com/s/7h39a0pqwxi4ets/2.%20A-nacci.doc */
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8.     class Program
  9.     {
  10.         static void Main()
  11.         {
  12.             int shift = 64;
  13.  
  14.             //Console.Write("Enter first member : ");
  15.             string firstMember = Console.ReadLine();
  16.             int first = firstMember[0] - shift; // (int)'A' = 65    first = 65-64 = 1
  17.  
  18.             //Console.Write("Enter second member : ");
  19.             string secondMember = Console.ReadLine();
  20.             int second = secondMember[0] - shift; // (int)'B' = 66  second = 66 - 64 = 2
  21.  
  22.             //Console.Write("Enter rows : ");
  23.             int rowsNumber = Int32.Parse(Console.ReadLine());
  24.  
  25.             //Console.WriteLine();
  26.  
  27.             Console.WriteLine((char)(first + shift));
  28.             if (rowsNumber  > 1)
  29.             {
  30.                 int next = first + second;
  31.  
  32.                 if (next > 26)
  33.                 {
  34.                     next = next % 26;
  35.                 }
  36.  
  37.                 string result = ((char)(second + shift)).ToString() + ((char)(next + shift)).ToString();
  38.                 Console.WriteLine(result);
  39.                 first = second;
  40.                 second = next;
  41.  
  42.  
  43.                 for (int i = 3; i <= rowsNumber; i++)
  44.                 {
  45.                     next = first + second;
  46.                     if (next > 26)
  47.                     {
  48.                         next = next % 26;
  49.                     }
  50.  
  51.                     first = second;
  52.                     second = next;
  53.  
  54.                     next = first + second;
  55.                     if (next > 26)
  56.                     {
  57.                         next = next % 26;
  58.                     }
  59.  
  60.                     first = second;
  61.                     second = next;
  62.                     Console.Write((char)(first + shift));
  63.                     Console.Write(new string(' ', i - 2));
  64.                     Console.WriteLine((char)(second + shift));
  65.                 }
  66.             }
  67.         }
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment