Advertisement
AnitaN

01.Intro-Programming-Homework/09.Print-Sequence

Mar 9th, 2014
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. //Problem 9.Print a Sequence
  2. //Write a program that prints the first 10 members of the sequence: 2, -3, 4, -5, 6, -7, ...
  3.  
  4. using System;
  5.  
  6. class PrintSequence
  7. {
  8.     static void Main()
  9.     {
  10.         Console.WriteLine("The First 10 members of sequence: 2,-3,4,-5,6,-7,...are:");
  11.         // use for loop  to show first 10 members of sequence  
  12.         for (int i = 2; i < 12; i++)
  13.         {
  14.             // if-else statement to Check even elements
  15.             if (i%2==0)
  16.             {
  17.                 //Print to Console positive even elements
  18.                 Console.WriteLine(i);    
  19.             }
  20.             else
  21.                 //Print to Console negative odd elements
  22.                 Console.WriteLine(-i);              
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement