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
What is the main reason that IT managers believe the future IT career model will be diamond-shaped, with few entry-level IT jobs
Valentin [98]
<span>In which career field, would the Computing Technology Industry Association's CompTIA A+ certification be useful?</span>
4 0
2 years ago
You have to display or connect to network shares on remote computers. Which command-line utility will you use to accomplish the
Xelga [282]

Answer:

net use X: \\SERVER\Share

Explanation:

1. Connect securely to the remote computer or ensure you have access to it on the network

2. then follow the step below:

Where X: is the drive letter you wish to map the share to, and \\SERVER\Share is the UNC path to the share. This should make the share visible in My Computer and the command line as well like all other shares mapped through the GUI.

In order to later disconnect the share, you would use

net use X: /delete

8 0
3 years ago
How are special characters added to a Word document? Check all that apply.
MrRissso [65]

It kinda depends on what you mean by special characters

7 0
2 years ago
Read 2 more answers
Some machine/items/gadget having only hardware​
shepuryov [24]
Yeh it’s becoz they work with hardware that’s why
6 0
2 years ago
Suppose an array of country codes and country names is created with a statement like this: $country_codes = array('DEU' =&gt; 'G
valentina_108 [34]

Answer:

Following are the code in the PHP Programming Language:

<u>foreach ($country_codes as $code => $name) { </u>

Explanation:

The following option is true because the Foreach statement only works on the objects and array and this statement is good for accessing the key and value pairs from the array.

So, that's why to print following associative array through echo statement we use the Foreach loop statement with following right condition.

<u>syntax</u>:

foreach (array as value)

{

  code or body to execute;

}

8 0
3 years ago
Other questions:
  • An IT technician has manually configured an IP address on a laptop for a new employee. Each time the employee tries to connect t
    8·1 answer
  • In addition to not parking where signs prohibit it, you should never park __________________.
    12·1 answer
  • What type of survey can help a network administrator make decisions about bands, channels, and widths when installing new access
    9·1 answer
  • If you have a mix of 32-bit and 64-bit versions of windows, which architectures should you add a unattended installation file fo
    7·1 answer
  • A user reports that she can't access the new server used in the accounting department. you check the problem and find out that h
    9·1 answer
  • Who was the 1st person to use the term television
    11·1 answer
  • What is output by the following C# code segment?int temp;temp = 180;while ( temp != 80 ) {if ( temp &gt; 90 ) {Console.Write( "T
    7·1 answer
  • Which of the following is considered both an input and output peripheral? Keyboard, Microphone, Speaker, Touchscreen monitor
    10·2 answers
  • How is science and technology used in the society​
    11·1 answer
  • The ______ Works on a single variable or constant. *​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!