Advertisement
Venciity

[SoftUni C#] Introduction - 09.PrintASequence

Mar 7th, 2014
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. // Write a program that prints the first 10 members of the sequence: 2, -3, 4, -5, 6, -7, ...
  2. using System;
  3.  
  4. class PrintASequence
  5. {
  6.     static void Main()
  7.     {
  8.         int a = 2;
  9.         int b = -3;
  10.  
  11.         for (int i = 0; i < 10; i = i + 2) // i = i + 2 because the program print 2 numbers while i < 10
  12.         {
  13.             Console.WriteLine("{0} {1}", a, b);
  14.             a = a + 2;
  15.             b = b - 2;
  16.         }
  17.  
  18.         //second variant
  19.  
  20.         //for (int i = 2; i <= 11; i++) // Минаваме през числата от 2 до 11 ( включително ).
  21.         //{
  22.         //    if (i % 2 == 0)
  23.         //    {
  24.         //        Console.WriteLine(i); // проверяваме дали числото е четно, ако да го печатаме
  25.         //    }
  26.         //    else
  27.         //    {
  28.         //        Console.WriteLine(-i); // ако не е - печатаме числото със знак минус
  29.         //    }
  30.         //}
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement