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();

Answer :

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.

Other Questions

what kind of tag will give additional info about your webpagechoices:a. b. c. <head>​ </span> </div> </a> <meta itemprop="position" content="5" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="https://reviewpoint.org/?question=10164206" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> गृहकाय के महतव को बताते हुए दो छात्रो के बीच संवाद लिखो।​ </span> </div> </a> <meta itemprop="position" content="6" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="https://reviewpoint.org/?question=27931868" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> the captain said we want victory at the cost any cost in the game that followed why did and Anif disobey his captain ​ </span> </div> </a> <meta itemprop="position" content="7" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="https://reviewpoint.org/?question=19303066" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> What are the factors that influence buoyancy and how are they related to it? ​ </span> </div> </a> <meta itemprop="position" content="8" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="https://reviewpoint.org/?question=45950419" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> If I were a bird, I could fly in the sky. (it is imaginary and unreal. A man can’t be a bird.) A. Conditional sentence B. Reported Speech C. Direct Speech D. Pa </span> </div> </a> <meta itemprop="position" content="9" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="https://reviewpoint.org/?question=2895193" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> What is the summary of chapter The rime of ancient mariner???? Pls ans it soon.. </span> </div> </a> <meta itemprop="position" content="10" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/?question=252164" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> Most jobs moved from the home to the factory and led to </span> </div> </a> <meta itemprop="position" content="11" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/?question=25216400" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> write F id the following is formatting tags, H for heading tags, S for structural tags, and SC if it belongs to a seperator/container tags.1. <div>2. <h1>3. <he </span> </div> </a> <meta itemprop="position" content="12" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/?question=25216401" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> Discuss challenges of change management in health care​ </span> </div> </a> <meta itemprop="position" content="13" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/?question=25216402" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> it starts at 10 and stops at 4​ </span> </div> </a> <meta itemprop="position" content="14" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/?question=25216403" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> Which terrestrial ecosystem is characterized by almost no rainfall, very hot days, and very cold nights? A. TundraB. Temperate forestC. DesertD. Grassland ​ </span> </div> </a> <meta itemprop="position" content="15" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/?question=25216404" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> What are two differences and two similarities between hyperplasia and cancer? </span> </div> </a> <meta itemprop="position" content="16" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/?question=25216405" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> Oo madamot na kung madamot..gusto ko ksi akin kalang..​ </span> </div> </a> <meta itemprop="position" content="17" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/?question=25216407" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> Can someone help me with letter b along with an explanation. </span> </div> </a> <meta itemprop="position" content="18" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/?question=25216408" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> aaaaaaaa PLEASE HELP ME I NEED THIS RN, PLS ANSWER THIS. (I’ll make you brainliest) link : https://youtu.be/q8NW9TiRfGA </span> </div> </a> <meta itemprop="position" content="19" /> </div><div itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/?question=25216409" class="brn-qpage-next-newest-questions__section js-qpage-newest-question"> <div class="sg-flex sg-flex--full-width sg-flex--margin-top-s sg-flex--margin-bottom-xs"> <span itemprop="name" class="sg-text sg-text--small sg-text--full sg-text--break-words sg-text--link sg-text--text-black sg-text--regular"> What is concurrent list? Mention any 4 subjects in the list? </span> </div> </a> <meta itemprop="position" content="20" /> </div> </div> </div> </div> <div class="brn-qpage-layout__right"> <div class="empty:sg-space-y-m md:empty:sg-space-y-l js-aside-content"> </div> <div class="brn-qpage-layout__right--full-height empty:sg-space-y-m md:empty:sg-space-y-l js-aside-content"> </div> </div> </div> <div class="brn-qpage-layout brn-qpage-layout__main js-main-container js-ads-screening-content sg-hide-for-medium-down"> <div class="js-react-app-billboard-above-footer"> </div> </div> </div> <div class="js-react-app-footer js-page-footer js-ads-screening-footer"> <footer role="contentinfo" class="sg-layout__footer"></footer> </div> </div> </div>