Question

Write a c# program in Microsoft visual studio to determine if the following numbers are even...

Write a c# program in Microsoft visual studio to determine if the following numbers are even or not.

Create an app that will read integers from an input file name Number.txt that will consist of one integer.

Determine which numbers are even and which are odd. Write the even numbers to a file named Even.txt and the odd numbers to a file named Odd.txt.

Number.txt

20
39
45
12
31
62
10
11
21
73
14
42
55
86
109
200
13
25
38
64

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is code:

using System;
using System.IO;

namespace ConsoleApp // Project name
{
class Program
{

static void Main(string[] args)
{
StreamWriter swEven = new StreamWriter("Even.txt", false);
StreamWriter swOdd = new StreamWriter("Odd.txt", false);
using (StreamReader sr = new StreamReader("Number.txt"))
{
string line;
// Read and display lines from the file until
// the end of the file is reached.
while ((line = sr.ReadLine()) != null)
{
if (int.Parse(line) % 2 == 0)
{
swEven.WriteLine(line);
}
else
{
swOdd.WriteLine(line);
}
}
}
Console.WriteLine("Done");
swEven.Close();
swOdd.Close();
Console.ReadKey();
}

}
}

Number.txt:

20
39
45
12
31
62
10
11
21
73
14
42
55
86
109
200
13
25
38
64

Even.txt:

20
12
62
10
14
42
86
200
38
64

Odd.txt:

39
45
31
11
21
73
55
109
13
25

Add a comment
Know the answer?
Add Answer to:
Write a c# program in Microsoft visual studio to determine if the following numbers are even...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (C++ Microsoft Visual Studio) [15 Points] Write a while loop to calculate the average of numbers...

    (C++ Microsoft Visual Studio) [15 Points] Write a while loop to calculate the average of numbers entered by the user:  Ask the user to enter an integer number or -1 to stop  Add the entered numbers  Compute the average of the numbers outside the loop after termination  Print the average

  • Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4...

    Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4 x 5 two-dimensional array. The program should use loops to populate the array using the rand, srand and time functions with random numbers between 10 and 60. After the values have populated the array, output the values of the array to the screen in something that looks like a 4 x 5 table.

  • using Microsoft Visual Studio C++ write a compute program that will allow the user to: 1.Get...

    using Microsoft Visual Studio C++ write a compute program that will allow the user to: 1.Get a Factorial (using a loop) 2. perform addition and subtraction 3.allow the user to quit the program

  • programming in Microsoft visual studio. Write a C++ program for the following algorithm. Compile, run, and...

    programming in Microsoft visual studio. Write a C++ program for the following algorithm. Compile, run, and verify the result by choosing some test data. Prompt user to write X1 value in double Read X1 Prompt user to write X2 value in double Read X2 Prompt user to write Y1 value in double Read Y1 Prompt user to write Y2 value in double Read Y2 Compute the lengths of the two sides of the right triangle generated by the two points...

  • C++ and Using Microsoft Visual Studio. Write 2 programs: One program will use a structure to...

    C++ and Using Microsoft Visual Studio. Write 2 programs: One program will use a structure to store the following data on a company division: Division Name (East, West, North, and South) Quarter (1, 2, 3, or 4) Quarterly Sales The user should be asked for the four quarters' sales figures for the East, West, North, and South divisions. The data for each quarter for each division should be written to a file. The second program will read the data written...

  • This program should use a main function and two other functions named playlist and savelist as...

    This program should use a main function and two other functions named playlist and savelist as follows: The main function: The main function should create an empty list named nums and then use a loop to add ten integers to nums, each integer in the range from 10-90. NOTE: In Python, a list is a data type. See Chapter 7. The main function should then call the playlist function and savelist function, in that order. Both of these functions take...

  • Write a program using C in Microsoft visual studios. Write a function that receives an array...

    Write a program using C in Microsoft visual studios. Write a function that receives an array of integers and the array length and prints one integer per line (Hint: Use \n for a line break). Left align all of the integers and use a field width of 10. Populate an array of 10 elements from the user and pass the array and its length to the function.

  • using visual studio 2) For each of the following, write C++ statements that perform the specified...

    using visual studio 2) For each of the following, write C++ statements that perform the specified task.. (Ref: classwork named pointer2) a) Declare a built-in array of type unsigned int called values with five elements, and initialize the elements to the even integers from 2 to 10. b) Declare a pointer vPtr that points to a variable of type unsigned int. c) Write two separate statements that assign the starting address of array values to pointer variable vPtr. d) Use...

  • o Write a function that outputs even numbers less than the input number. • Function name...

    o Write a function that outputs even numbers less than the input number. • Function name should be 'evenprint'. • A number is given as input to the function. . The function must return a list of even numbers def evenprint(num): #write statement >[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74,...

  • C++

    You are given a file results.txt with the results of an experiment as a set of integers. You need to separate these results into three categories: negative integers, even positive integers, and odd positive integers. A sample of the file results.txt is shown below:    52    49   -22    31   -66    41   -94   -45   -91   -81    65    39   -37    90   -94   -12   -24    53    59   -63    -2   -11    29    42    51   -45    36    31   -68   -77     0    92   -32    17   -56    51  ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT