Question: Exercise 11: Code that adds numbers from 1 to 100 two ways: Gauss's way and the naive programs. Both programs will prompt the user for

 Exercise 11: Code that adds numbers from 1 to 100 two

Exercise 11: Code that adds numbers from 1 to 100 two ways: Gauss's way and the naive programs. Both programs will prompt the user for an integer n from the command line, read it in, check that it is indeed an integer, and print a confirmation of the number from main, then call a function to compute the sum from 1...n. If n is not an integer the program should terminate with an appropriate message way. For this exercise you will write two small C upon checking n (and therefore not proceed or call any functions.) The first program will be named BruteForceAdder.cc. After printing n, the main function of BruteForceAdder.cc will call a function named BruteForceAdder and pass this function n. The function BruteForceAdder will print a message to the screen telling the user that it has begun adding the numbers from 1 to n. This function will then proceed to add the numbers from 1 to n the brute force way: in a loop. The program will print the sum with a nice, descriptive message, and terminate The second program will be named GaussAdder.cc. After printing n, the main function of GaussAdder.cc will call a function named GaussAdder and pass this function n. The function GaussAdder will print a message to the screen telling the user that it has begun adding the numbers from 1 to n. This function will then proceed to add the numbers from 1 to n the Gaussian way: i= 1 The program will print the sum with a nice, descriptive message, and terminate Run both of these programs with a large value of n from a bash shell, using the Linux time command. What does the time command tell you about the performance of both programs? Try increasingly larger value of n, for example scaling up to the the billions. How much does it matter to implement an intelligent algorithm versus a brute force one

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!