Advertisement
AnitaN

01.Intro-Programming-Homework/16.Print-Long-Sequence

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