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...
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...
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
Collapse Write a program that prompts the user to input a positive integer. It should then...
Collapse Write a program that prompts the user to input a positive integer. It should then output a message indicating whether the number is a prime number. (Note: An even number is prime if it is 2. An odd integer is prime if it is not divisible by any odd integer less than or equal to the square root of the number.) Turn in: Your source code for with The name of your program as a comment at the top...
4) Write a Java program using Conditions: Write a program where it will ask user to...
4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has. Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input 2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and...
For this assignment you need to write a parallel program in C++ using OpenMP for vector...
For this assignment you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is: #pragma...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT