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)
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...
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]
The following code generates a list arr with 100 items. import random random.seed(0) arr = [...
The following code generates a list arr with 100 items. import random random.seed(0) arr = [ random.randint(1,100) for _ in range(100) ] Write a program that computes the sum of squares of all the numbers in the list arr Submit both the code and result (sum of squares of all the numbers in arr)
In this project, you will write C code to solve the Collatz conjecture using ordinary pipes...
In this project, you will write C code to solve the Collatz conjecture using ordinary pipes to share data between parent and child processes Here are the rules for your program: The starting number will be entered on the command line. Be sure to check that it is positive. The parent will handle the command line and pass the integer to the child. The child will do the calculation and pass the sequence generated back to the parent. The parent...
write a code in jave where you have to Populate even and odd number array. plz...
write a code in jave where you have to Populate even and odd number array. plz explain it clearly and make sure the code run
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT