1) Write a C++ program that contains a loop that will calculate the (sum(i*0.75)) from 1 up to n, where n is sufficiently large to require about 30 seconds to complete, you might want to use nested loops. (You can find out how long a program takes by using the LINUXtime command). The program should not require any inputnor generate any output except possibly at the end. Include comments to describe the program and identify you as the author of the program. • Use the LINUXtime command to execute your program as a Foreground process and time it. Example: time program1 • Use “&” to execute the program as a background process several times. Example: programName& (use “time” to measure it as well) • Use the ps command to monitor its execution in the background.
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
1) Write a C++ program that contains a loop that will calculate the (sum(i*0.75)) from 1 up to n, where n is sufficiently large to require about 30 seconds to complete, you might want to use nested loops.
(You can find out how long a program takes by using the LINUXtime command). The program should not require any inputnor generate any output except possibly at the end. Include comments to describe the program and identify you as the author of the program.
• Use the LINUXtime command to execute your program as a Foreground process and time it.
Example: time program1
• Use “&” to execute the program as a background process several times.
Example: programName&
(use “time” to measure it as well)
• Use the ps command to monitor its execution in the background.
2) Create two more C++ programs, similar to the above program, except that, they take about 75, and 120 seconds respectively to execute.( 3 in total 30, 75, and 120 seconds)
with the following Commands :
-time:
-Outputs 3 separate time indicators
-Real time, user time, and sys time
-User time: time the program spent executing user functions, ex: loops, or indexing user defined arrays
-Sys time: time the program spent executing system functions, like memory allocations, variable setups, loading libraries, call system utilities.
-Real time: total time the program was running, from start to finish, similar if you used a stopwatch to time the program.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images