68 369
Assignments Done
98,7%
Successfully Done
In November 2018

Answer to Question #29110 in C# for bhavna

Question #29110
create a console program to create a file of numbers then store even & odd numbers of that file in two seperate files
Expert's answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Evenandodd_numbers
{
class Program
{
static void Main(string[] args)
{
int []arrayofnumbers=new int[1000];//variable for numbers
int []arrayofevennumbers=new int[1000];//variable for even numbers
int []arrayofOddnumbers=new int[1000];//variable for odd numbers
Random rand=new Random();
//fill array of random numbers
for (int i = 0; i < 1000; i++) {
arrayofnumbers[i] = rand.Next(1,1000);
}
int counteven = 0;//count for even numbers
int countodd = 0;//count for odd numbers
for (int i = 0; i < 1000; i++)
{
//check if number is even
if (arrayofnumbers[i] % 2 == 0)
{
arrayofevennumbers[counteven] = arrayofnumbers[i];//add even numbers to array
counteven++;
}
//check if number is odd
else {
arrayofOddnumbers[countodd] = arrayofnumbers[i];//add odd numbers to array
countodd++;
}
}
//save even numbers
using (System.IO.StreamWriter file = new
System.IO.StreamWriter("even.txt", true))
{
for (int i = 0; i < counteven; i++)
{
file.WriteLine(arrayofevennumbers[i].ToString()); ;//save array to file
}
}
//save Odd numbers
using (System.IO.StreamWriter file = new
System.IO.StreamWriter("Odd.txt", true))
{
for (int i = 0; i < countodd; i++)
{
file.WriteLine(arrayofOddnumbers[i].ToString());//save array to file
}
}

}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions