Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace P2
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Se da secv. 1, 1, 2, 1, 2, 3, ... Sa se afiseze primele n elemente ale sirului.");
- Console.Write("n = ");
- int n;
- if (int.TryParse(Console.ReadLine(), out n) && n >= 1)
- {
- int rand = 1, valoare_curenta, contor = 0, k;
- bool break2;
- while (true)
- {
- break2 = false;
- valoare_curenta = 1;
- for (k = 1; k <= rand; k++)
- {
- Console.Write("{0} ", valoare_curenta);
- valoare_curenta++;
- contor++;
- if (contor == n) {
- break2 = true;
- break;
- }
- }
- if (break2)
- {
- break;
- }
- rand++;
- }
- }
- else
- {
- Console.WriteLine("Pentru n introduceti un numar natural nenul.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment