Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem 9.Print a Sequence
- //Write a program that prints the first 10 members of the sequence: 2, -3, 4, -5, 6, -7, ...
- using System;
- class PrintSequence
- {
- static void Main()
- {
- Console.WriteLine("The First 10 members of sequence: 2,-3,4,-5,6,-7,...are:");
- // use for loop to show first 10 members of sequence
- for (int i = 2; i < 12; i++)
- {
- // if-else statement to Check even elements
- if (i%2==0)
- {
- //Print to Console positive even elements
- Console.WriteLine(i);
- }
- else
- //Print to Console negative odd elements
- Console.WriteLine(-i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement