Question

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

Homework Answers

Answer #1
/*
 *  Program to print numbers from range low to up that are not divisible by n
 */

using System;
public class Exercise2  
{
  public static void Main() 
  {
    int low, up, n;
    
    // retrieving n integers from the console
    Console.Write("Enter lower key: ");
    low = Convert.ToInt32(Console.ReadLine());
    Console.Write("Enter upper key: ");
    up = Convert.ToInt32(Console.ReadLine());
    Console.Write("Enter n: ");
    n = Convert.ToInt32(Console.ReadLine());
    
    Console.Write("\nOutput: ");
    for (int i = up; i >= low; i--)
    {
      if (i % n != 0)
        Console.Write(i + " ");
    }
  } 
}
/*  Program ends here */

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
Write a program to find all the numbers divisible by 7 between a given range of...
Write a program to find all the numbers divisible by 7 between a given range of numbers [n1, n2] entered by the user using a FOR loop only. write C program. help
C program question: Write a small C program connect.c that: 1. Initializes an array id of...
C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and changing all the entries with the same name as p to...
Python Programming 4th Edition: - Write a program that test and display if a number enter...
Python Programming 4th Edition: - Write a program that test and display if a number enter is divisible by 2 and/or 3. Hints: - Use the correct operation - Prompt the user to enter a number The output should look like as follows - Enter an integer: --Number is divisible by 2 and 3 --Number is divisible by either 2 or 3, but not both --Number is not divisible by either 2 or 3
Write a Python program prints out the unique elements of a list lst in a sorted...
Write a Python program prints out the unique elements of a list lst in a sorted manner (i.e it removes duplicates from the list). For example, if list is [10,20,30,20,10,50,60,40,80,50,40], the output should be [10, 20, 30, 40, 50, 60, 80].?
Write a program to solve the classic FizzBuzz problem. The program should output integers 1 thru...
Write a program to solve the classic FizzBuzz problem. The program should output integers 1 thru 100, one to a line.However, if the number is divisible by 3 it should output Fizz instead of the number; if the number is divisible by 5 it should output Buzz instead of the number and if it is divisible by both 3 and 5, it should output Fizz Buzz instead. write in C
/* This program should check if the given integer number is prime. Reminder, an integer number...
/* This program should check if the given integer number is prime. Reminder, an integer number greater than 1 is prime if it divisible only by itself and by 1. In other words a prime number divided by any other natural number (besides 1 and itself) will have a non-zero remainder. Your task: Write a method called checkPrime(n) that will take an integer greater than 1 as an input, and return true if that integer is prime; otherwise, it should...
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.
Develop a program that will sort the elements of a single dimension array. Program Requirements: 1....
Develop a program that will sort the elements of a single dimension array. Program Requirements: 1. Declare a single dimension array of size n 2. Input n elements to a single dimension array 3. Sort the elements of an array from highest to lowest and vice versa Also, the program will identify and output the highest and lowest integer.
Task 1: Program Analysis Write a function cutEdges that removes the first and the last two...
Task 1: Program Analysis Write a function cutEdges that removes the first and the last two items from a list given as its argument.  The existing list should be changed in-place; the function should not return anything..programmed in python
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.