Question

Write the code in C# List the evens or the odds. You are given a lower...

Write the code in C#

List the evens or the odds. You are given a lower and an upper bound for a range of integer numbers. Then a command specifies if you need to list all even or odd numbers in the given range.

Homework Answers

Answer #1
using System;

public class SequenceEvenOdd
{
    public static void Main(string[] args)
    {
        Console.Write("Enter upper bound: ");
        int upper = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter lower bound: ");
        int lower = Convert.ToInt32(Console.ReadLine());
        Console.Write("Do you want to display even or odd? ");
        bool odds = Console.ReadLine().Equals("odd", StringComparison.OrdinalIgnoreCase);
        for (int i = lower; i <= upper; i++)
        {
            if (odds && i % 2 == 1)
            {
                Console.WriteLine(i);
            }
            if (!odds && i % 2 == 0)
            {
                Console.WriteLine(i);
            }
        }
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The code needs to be in C #. You can define the upper and lower bounds....
The code needs to be in C #. You can define the upper and lower bounds. Q. You are given a lower and an upper bound for a range of integer numbers. Write a program that prints the range of numbers in the reverse order and prints it back on the original order.
Write Java code that creates an array of primitive integers named odds and stores all odd...
Write Java code that creates an array of primitive integers named odds and stores all odd numbers between -6 and 38 using a for loop. (Your code will populate the array.) Your code should also enable the array’s size to be exactly large enough to store the numbers. (You will not put a number for the size, your code will determine the number.) (5 pt)
Write a program in python 3 that uses a custom function to generate a specified number...
Write a program in python 3 that uses a custom function to generate a specified number of random integers in a specified range. This custom function should take three arguments; the number of integers to generate, the lower limit for the range, and the upper limit for the range. Values for these arguments should be entered by the user in main. The custom function should display the random integers on one line separated by single spaces. The function should also...
using dr.racket programing language If we write a function that tests whether a list contains only...
using dr.racket programing language If we write a function that tests whether a list contains only strings, odd numbers, or even numbers, you will notice that the code that iterates through the list stays the same, with the only change being the predicate function that checks for the desired list element. If we were to write a new function for each of the tests listed above, it would be more error-prone and an example of bad abstraction. We could write...
Please write code in C. Thank you! Write a program that reads a list of integers,...
Please write code in C. Thank you! Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending order. The input begins with an integer indicating the number of integers that follow. You can assume that the list will have at least 2 integers and less than 20 integers. Ex: If the input is: 5 10 5 3 21 2 the output is: 2 3 To achieve the above, first read...
Write a C++ program to print all the perfect numbers below a certain given number. A...
Write a C++ program to print all the perfect numbers below a certain given number. A perfect number is a number that that is equal to the sum of it's divisors other than itself . For example, 6 and 28 are all perfect numbers. 6 = ( 1+2 +3) 28 = (1+2+4+7+14) Make sure your program conforms to the following requirements: 1. Accept the upper limit from the user (as an integer). (5 points) 2. Make sure the number is...
Write C language code for a function that takes a doubly linked list as a parameter...
Write C language code for a function that takes a doubly linked list as a parameter and deletes all the nodes in even positions from the first to the last after displaying the content of each node to the console.
Write a program in C# that reverses a collection and removes elements that are divisible by...
Write a program in C# that reverses a collection and removes elements that are divisible by a given integer n. You will give the lower and upper limits for the range of elements and the integer n, like 1, 6, 2. Your output should be 5,3,1
Write (and test) a Python function that rearranges a sequence of integer values so that all...
Write (and test) a Python function that rearranges a sequence of integer values so that all the even values appear before all the odd values. Make sure to test all common use-cases (ie, an array with all even numbers, one with all odd numbers, and one with a mixture of odd and even numbers). What is the running time of your algorithm? Justify your answer. just not the solution, also need to understand it. Thanks
Write an R code to print out all even numbers from the following numbers list in...
Write an R code to print out all even numbers from the following numbers list in the same order they are received. Write the code so it does not print any numbers that come after 83. numbers = [951, 40, 84, 51, 60, 69, 48, 19, 61, 85, 98, 50, 72, 47, 44, 61, 83, 65, 41, 51, 63, 61, 65, 75, 21, 30, 84, 92, 23]