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

Write a program (in Q0.c) to do the following: In main(), declare an integer x. Print...
Write a program (in Q0.c) to do the following: In main(), declare an integer x. Print the address of x (using the address-of operator). Pass x as an argument to a function void fooA(int* iptr). (Hint: can you pass x itself directly?) In fooA(int* iptr), print the value of the integer pointed to by iptr, the address pointed to by iptr, and the address of iptr itself. In the main function, following the call to fooA(...) , print the value...
complete a pseudocode for the program specifications be sure to declare the contants and it contains...
complete a pseudocode for the program specifications be sure to declare the contants and it contains only 1 if-else statement you need a program that will calculate the net pay for the employees. Input consists of the employee’s first name, employee’s last name, hourly pay rate, hours worked. The gross pay is based on the hours worked. If the hours worked is over 40, then the overtime pay is one and a half times the hourly pay rate for all...
complete a pseudocode for the program specifications be sure to declare the contants and it contains...
complete a pseudocode for the program specifications be sure to declare the contants and it contains only 1 if-else statement You need a program that will calculate the cost of movie tickets. Input will consist of the customer’s name and age. The output is to consist of the customer’s name and ticket cost. If the age is 12 or less, the ticket cost is $5.00. If the age is over 12, the ticket cost is $8.95.
Write the following Java code into Pseudocode import java.util.*; public class Main { // Searching module...
Write the following Java code into Pseudocode import java.util.*; public class Main { // Searching module public static void score_search(int s,int score[]) { // Initialise flag as 0 int flag=0; // Looping till the end of the array for(int j=0;j<10;j++) { // If the element is found in the array if(s==score[j]) { // Update flag to 1 flag=1; } } // In case flag is 1 element is found if(flag==1) { System.out.println("golf score found"); } // // In case flag...
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
pseudocode The main( ) program passes these integer values as arguments to the findMax( ) method...
pseudocode The main( ) program passes these integer values as arguments to the findMax( ) method for further processing. The main program receives one result back from findMax( ) method and displays the maximum of these three integer values. The findMax( ) method simply receives three integer values from the main program and finds the maximum of three integers and returns one value back to the caller (in this case the main application).
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]...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT