TASK 5: Write a
Step 1
Parallelized loop means, The loop which doesn't depend on the previous loop and all iterations are independent.
That means, if we take a for loop as an example:
for(int i=0;i<n;i++){
a[i]=i+50;
}
In this loop each iteration is not depend on any previous levels.
If we consider another example:
for(int i=0;i<n;i++){
a[i]=a[i-1]+1;
}
In this it is depend on previous iteration.so it is not comes under parallelized loop.
Step 2
Now, consider a C program with parallelized loop:
#include<stdio.h>
int main(){
int n, i, a[100];
printf("Enter a number: ");
scanf("%d",&n);
for(i=0; i<n; i++){
a[i] = i+50;
printf("%d ",a[i]);
}
return 0;
}
Step by stepSolved in 3 steps with 1 images
- Construct a single for loop to print out the following lines. You may use as many variables as you wish, but you may not use multiple loops. 4 4 4 8 2 7 16 1 10 32 0.5 13 64 0.25 16arrow_forwardCHALLENGE ACTIVITY 5.2.3: Basic while loop expression. Write a while loop that repeats while user_num ≥ 1. In each loop iteration, divide user_num by 2, then print user_num.Sample output with input: 2010.0 5.0 2.5 1.25 0.625 Note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds and report "Program end never reached." The system doesn't print the test case that caused the reported message.arrow_forwardA credit card company awards monthly reward points (integer type) based on the type of membership a customer has and the amount they charge to their card that month. The user will enter the membership type and purchase amount, then determine the appropriate number of reward points. Use a pretest loop to allow the user to enter data until they input 0 for the purchase amount. Do all of your output in main(). Make it look like this. Don’t forget your underlines won’t be immediately underneath. Use methods for the following: getPurchaseAmt() Get the monthly purchase amount from the user. Include an error-trap around this input value so the user will have to enter a positive number (0r 0 to end the loop). Return the purchase amount. displayMenu() Display a menu of the membership types for the user to choose from, as follows: Membership Types: Premium Plus Standard Enter choice (1, 2, or 3): This method only displays. There is nothing to return, so it will be a void method. You will…arrow_forward
- # TASKS # 1. Add a line of code to find and print the length of 'list_of_powers' # 2. Modify the upper limit of the loop to be 100000 and run the program again # 3. Find and print the maximum and minimum number in the list # 4. Add a while loop which will check to make sure the number entered by the user is a positive number A# 5. Add comments to the code below to explain what is happening i = 0 UPPER_LIMIT = 10000 list_of_powers = [] power = int(input("Enter a power \n")) Ewhile (i**power < UPPER_LIMIT): list_of_powers.append(i**power) i += 1 print(list_of-powers)arrow_forwardThe second image shows the final result but I just want to know how we get there, thanks!arrow_forwardpython question Implement the following:1) Use a loop to continuously request an integer input from the console.2) As long as the value is in the range from -10 to 10 inclusive, request new values.3) Once the value is not in the range above, end the loop.4) Prompt a message and print the sum of all valid values.Input text can be any content. Just make sure to precisely match the output format below.Write your code in the ANSWER area provided below (must include comments if using code is not covered in the course).Example OutputEnter a number (-10, 10): 0Enter a number (-10, 10): 1Enter a number (-10, 10): -1Enter a number (-10, 10): 11Number out of range entered. Loop terminates.0arrow_forward
- sentinel: a value used to stop a while loop from executing. Exercises 1. Write a program that uses a for loop to compute the power of a number. For example, 2 to the third power is 8.arrow_forwardCreate a program called loopExercise. Prompt the user to enter two values (indicate the range). Use a while loop to generate two random values using an appropriate range. The loop should be controlled by the two values entered. Once both values have been randomly generated, the loop should terminate. Include a counter variable to count the number of iterations. Once the loop terminates, print the final randomly generated values and the number of iterations it took to generate those two values. Use logical operators where appropriate. Submit code. JAVAarrow_forwardPython A program to calculate the value of some change in dollars Code evaluation (What is the result of the following code?)- Short sentence(What is the difference between X and Y?)- Translation (Convert the following code from a for loop to a while loop)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education