1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
SashulF [63]
3 years ago
8

Write a program that first calls a function to calculate the square roots of all numbers from 1 to 1,000,000 and write them to a

file named: roots.txt (See output on page 3) 2.) Write a program then calls a function to calculate the squares of all numbers from 1 to 1,000,000 and write them to a file named: squares.txt 3.) Here are the function prototypes: void writeRoots(); void writeSquares();
Computers and Technology
1 answer:
svlad2 [7]3 years ago
3 0

Answer:

The csharp program to compute square roots of numbers and write to a file is as follows.

class Program  

{  

static long max = 1000000;  

static void writeRoots()  

{  

StreamWriter writer1 = new StreamWriter("roots.txt");  

double root;  

for (int n=1; n<=max; n++)  

{  

root = Math.Sqrt(n);  

writer1.WriteLine(root);  

}  

}  

static void Main(string[] args)  

{  

writeRoots();  

}  

}

The program to compute squares of numbers and write to a file is as follows.

class Program  

{  

static long max = 1000000;  

static void writeSquares()  

{  

StreamWriter writer2 = new StreamWriter("squares.txt");  

long root;  

for (int n = 1; n <= max; n++)  

{  

root = n*n;  

writer2.WriteLine(root);  

}  

}  

static void Main(string[] args)  

{  

writeSquares();  

}  

}  

Explanation:

1. An integer variable, max, is declared to hold the maximum value to compute square root and square.

2. Inside writeRoots() method, an object of StreamWriter() class is created which takes the name of the file as parameter.

StreamWriter writer1 = new StreamWriter("roots.txt");

3. Inside a for loop, the square roots of numbers from 1 to the value of variable, max, is computed and written to the file, roots.txt.

4. Similarly, inside the method, writeSquares(), an object of StreamWriter() class is created which takes the name of the file as parameter.

StreamWriter writer2 = new StreamWriter("squares.txt");

5. Inside a for loop, the square of numbers from 1 to the value of the variables, max, is computed and written to the file, squares.txt.

6. Both the methods are declared static.

7. Inside main(), the method writeRoots() and writeSquares() are called in their respective programs.

8. Both the programs are written using csharp in visual studio. The program can be tested for any operation on the numbers.

9. If the file by the given name does not exists, StreamWriter creates a new file having the given name and then writes to the file using WriteLine() method.

10. The csharp language is purely object-oriented language and hence all the code is written inside a class.

You might be interested in
Which of the following are ways that
Viefleur [7K]

Answer:

A and b

Explanation:

3 0
2 years ago
Wireframing and storyboarding are helpful in which step of web development?
Thepotemich [5.8K]
Since wireframing and storyboarding are both part of the developing phase, I would think that the answer is Planning
4 0
3 years ago
Read 2 more answers
Summarize who you believe cyber criminals are, and why?
sergij07 [2.7K]

Answer:

 The cyber criminals are the people that are engaged with getting the data in an unapproved way and furthermore mischief to the association henceforth are considered as cyber criminals.

Cyber criminals are people or groups of individuals who use innovation to committed the malicious exercises on computerized frameworks or systems with the aim of taking the organization data or individual information and producing benefit.

There are many types of cyber criminals that are:

  • Internet stalkers
  • Cyber terrorist
  • Identity thieves

5 0
3 years ago
A good first step to understanding any kind of text is to :
Vitek1552 [10]

Answer:

find the main idea

Explanation:

6 0
2 years ago
What port number is the web server listening on for the web request?
Veronika [31]
80 for HTTP, 443 for HTTPS
8 0
3 years ago
Other questions:
  • Why would you want to minimize the Ribbon?
    11·1 answer
  • What exactly does the value recorded in a single dimension of a sift keypoint descriptor signify?
    15·1 answer
  • Consider the following code segment.
    15·1 answer
  • What is infinite recursion?
    7·1 answer
  • Power point presentation make use of pages known as
    9·2 answers
  • In a finite state machine, state transitions happen only: a. When the reset causes a clock pulse on the D outputs of the flip-fl
    11·1 answer
  • In two to three sentences, define "home row" and explain why it is important.
    6·2 answers
  • Which of the listed tools would a barber likely use in the following scenario?
    15·1 answer
  • A.Distance sensor<br> b.Programable microcontroller<br> c.Ambient light sensor<br> d.Wi-Fi
    9·2 answers
  • You are planning to depart on a flight from area 2 to area 4 in 12 hours. What weather is forecast to occur along your route?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!