Question

In: Computer Science

assume that the following pseudocode is executed in a program module main declare x = 1...

assume that the following pseudocode is executed in a program
module main
declare x = 1
declare sum = 0
declare max = 5
while ( x < max)
Display "x is ", x
set x = x + 1
set sum = s + x
end while
end module

after the execution of this program the final value of x is_____ and the final value of sum is_____

Solutions

Expert Solution


Solution) Dear Student, after execution

FINAL VALUE OF X = 5 and

FINAL VALUE OF SUM=14



we can get the solution by writing a simple c++ code:

#include <iostream>

using namespace std;

int main(){
int x=1, sum=0;  //declaration of x and sum.


while(x < 5){ 
   cout<<"now x is:"<<x<<endl;  //x will be printing for each iteration
                                //which is till 1 to 4.
   x=x+1;
   sum = sum + x;
   
   cout<<x<<endl;  //Value of x
   
   cout<<sum<<endl;  //Value of sum
}

return 0;
}
Sample output:


now x is:1                                                                                                                      
2                                                                                                                               
2                                                                                                                               
now x is:2                                                                                                                      
3                                                                                                                               
5                                                                                                                               
now x is:3                                                                                                                      
4                                                                                                                               
9                                                                                                                               
now x is:4                                                                                                                      
5                //Final Value of x                                                                                                               
14               //Final value of sum

Related Solutions

A customer in a store is purchasing two items. Design a program using module pseudocode that...
A customer in a store is purchasing two items. Design a program using module pseudocode that asks for the price of each item in dollars, and then displays three things in their output receipt - the subtotal of the sale in dollars, the amount of sales tax in dollars and the final amount paid by the customer in dollars. Assume the sales tax is 4 percent.
Write a program in c++ to do the following : (1) Declare an array a of...
Write a program in c++ to do the following : (1) Declare an array a of size 10 and three pointer variables p, q, and v. (2) Write a loop to fill array a with values 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 (3) write following statement: p= &a[2]; q = &a[5]; i = *q - *p; cout<<“The value of i is”<< i; i = *p - *q; cout<<“The value of i is %d”<< i; 4) assign...
How many times is line (5) executed in the following pseudocode? Enter your answer in the...
How many times is line (5) executed in the following pseudocode? Enter your answer in the box below. NOTE: Please read the pseudocode very carefully. (1) n=14n=14 (2) m=16m=16 (3) for i=1i=1 to n+2n+2 (4) ---- for j=1j=1 to mm (5) -------- print (i,j)
C++ Vectors. Create a program do the following in the program: 1. declare an vector without...
C++ Vectors. Create a program do the following in the program: 1. declare an vector without specifying the size 2. use push_back to add random integers between 100 and 999 to the vector 3. write a function that returns the smallest, largest, and average of the numbers in the vector display the smallest, largest, and average of the numbers in the vector
Rewrite your program for part 1. Do not declare the array globally, declare it in the...
Rewrite your program for part 1. Do not declare the array globally, declare it in the loop function. This now requires that you add two parameters to your fill array and print array functions. You must now pass the array name and array size as arguments, when the program calls these functions. The program has the same behavior as problem 1, but illustrates the difference between globally and locally declared variables. The program code for part 1 was: int Array[15]...
Assume that for a given program 70% of the executed instruction are arithmetic, 10% are load/store,...
Assume that for a given program 70% of the executed instruction are arithmetic, 10% are load/store, and 20% are branch. i. Given the instruction mix and the assumption that an arithmetic instruction requires 2 cycles, a load/store instruction takes 6 cycles, and a branch instruction takes 3 cycles, ?nd the average CPI. ii. For a 25% improvement in performance, how many cycles, on average, may an arithmetic instruction take if load/store and branch instructions are not improved at all.
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an...
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an integer pointer p. 3. Let p pointing to the array a[ ]. 4. Use p (you have to use p) to put 0 into the first element of this array, 2 into the second element, 4 into the 3rd element, 6 into the 4th element, ... 198 into the 100th element of this array. 5. Use a (you have to use a) to display...
Create and submit a Python program (in a module) that contains a main function that prints...
Create and submit a Python program (in a module) that contains a main function that prints 17 lines of the following text containing your name: Welcome to third week of classes at College, <your name here>! can someone please show me how to do this step by step? I'm just confused and keep getting errors in idle.
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
C++ program, FOR THE MAIN WHEN YOU DECLARE FUNCTION PLEASE PUT CORNER SIZES IN A TABLE...
C++ program, FOR THE MAIN WHEN YOU DECLARE FUNCTION PLEASE PUT CORNER SIZES IN A TABLE AND A LOOP SO YOU DON'T HAVE TO DECLARE FUNCTION MULTIPLE TIME You may work in groups of two. Your job is to write a function makeSpiral() that takes a two-dimensional array and the number of rows and columns to fill. The function will fill the rows-by-columns corner of the array with the integers from 1 to (rows * columns) in a counter-clockwise spiral...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT