Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace _9.PrintSequence
- {
- class PrintSequence
- {
- static void Main(string[] args)
- {
- string members = "2, -3, 4, -5, 6, -7";
- Console.WriteLine("If your sequence of numbers is: {0}", members);
- Console.WriteLine("The first 10 members are:");
- // to find all members of the sequence we can use for loop
- for (int index = 2; index <= 11; index++)
- {
- // Console.Write(index + " ");
- // prints the numbers between 2 and 11 (our first 10 members)
- int result = index % 2;
- // dividing by 2 we can find the odd and even numbers in the sequence
- //Console.WriteLine(result + " ");
- //prints 0 for odd and 1 for even number in the sequence
- if (result != 0) // we can use if loop to separate odd from even numbers
- {
- Console.Write(" -{0}, ", index);
- // prints odd numbers in the sequence (our negative members)
- }
- else
- {
- Console.Write("{0},", index);
- // prints even numbers in the sequence (our positive members)
- }
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement