silviubogan

Problema 2 / Tema 21.10.2014 / Curs Fundamentele programarii

Oct 23rd, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2.  
  3. namespace P2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.WriteLine("Se da secv. 1, 1, 2, 1, 2, 3, ... Sa se afiseze primele n elemente ale sirului.");
  10.             Console.Write("n = ");
  11.             int n;
  12.             if (int.TryParse(Console.ReadLine(), out n) && n >= 1)
  13.             {
  14.                 int rand = 1, valoare_curenta, contor = 0, k;
  15.                 bool break2;
  16.                 while (true)
  17.                 {
  18.                     break2 = false;
  19.                     valoare_curenta = 1;
  20.                     for (k = 1; k <= rand; k++)
  21.                     {
  22.                         Console.Write("{0} ", valoare_curenta);
  23.                         valoare_curenta++;
  24.                         contor++;
  25.                         if (contor == n) {
  26.                             break2 = true;
  27.                             break;
  28.                         }
  29.                     }
  30.                     if (break2)
  31.                     {
  32.                         break;
  33.                     }
  34.                     rand++;
  35.                 }
  36.             }
  37.             else
  38.             {
  39.                 Console.WriteLine("Pentru n introduceti un numar natural nenul.");
  40.             }
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment