Question

For the following questions, simply type your answer in the space provided with each question. Simply...

For the following questions, simply type your answer in the space provided with each question. Simply translate the provided code segment in the specified language (C++).

  1. Rewrite the following pseudocode segment in C++ using the loop structures (for and while). Assume that all the variables are declared and initialized.

k = (j + 13) / 27

loop:

      if k > 10 then goto out

      k = k + 1

      i = 3 * k - 1

      goto loop

out: . . .

Homework Answers

Answer #1

Ans

In while loop:-

initialize;

while(loop condition){

statement;

flow statement;

}

in for loop:-

for(initialize; loop condition;flow){

statement;

}

Here loop condition is !(k>10) because when k>10 it comes out. flow statement k=k+1;

.

Using while:-

code:-

k=(j+13)/27;

while(!(k<10)){

k=k+1;

i=3*k-1;

}

..

.

Using for:-

code:-

for(k=(j+13)/27;!(k<10);k++){

i=3*k-1;

}

.

..

.

If any doubt ask in the comments.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Question 1. Answer the following questions on MIPS Instruction Set. a) Show the minimal sequence of...
Question 1. Answer the following questions on MIPS Instruction Set. a) Show the minimal sequence of MIPS instruction for the following pseudocode segment: A[3] = A[10] + B; Assume that B corresponds to register $t3 and the array A has a base address of 1000C41016 which is required to be loaded to register $t0 in your code. Provide comments for each line of your MIPS instruction. b) Assume that Loop starts at memory location 0xC010. Provide a) instruction format of...
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.    ...
This is a homework assignment for Computer Architecture and some question use MIPS Assembly language. 1.     In the following MIPS assembly code, translate all the instructions to their corresponding machine code in hexadecimal format. This code is stored in the memory from address 0x1fff0000. Loop: sw $t1, 4($s0)        addi $t1, $t1, -1    sll $t1, $t1, 2        bne $t1, $s5, Exit    addi $s0, $s0, 4          j Loop Exit: … 2.     Find the MIPS...
# Question 2 for HW 3 use MPLAB IDE # Your solution should implement the following...
# Question 2 for HW 3 use MPLAB IDE # Your solution should implement the following loop: # for (i = 0; i < X; i++) { # A = A + X; # B = B - X; # if (A == B) # break; ## break exits loop early # } .global main .data ### THESE VARIABLES ARE SIMPLY GIVEN VALUES TO START ### WITH--CHANGE THEIR VALUES AND VERIFY YOUR PROGRAM ### WORKS APPROPRIATELY IN ALL CASES A:...
Consider the following program listing that is written in the C Language: #include <msp430.h> void main(void);...
Consider the following program listing that is written in the C Language: #include <msp430.h> void main(void); { WDTCTL = WDTPW|WDTHOLD; unsigned char a=0x14; unsigned char b=0xDC; unsigned char c,d,e,f; c = a^b; d = a|b; e = ~d; f = ~e; while(1); } 1) Are the declared data types local or global variables? 2) Perform bitwise logical analysis to determine the unknown values of the given logic expressions. 3) Show the correct addresses and contents for all variables in the...
Multiple Choice: The following function is intended to return the value of a[1] + a[2] +...
Multiple Choice: The following function is intended to return the value of a[1] + a[2] + … + a[n] for n ≥ 1. (The sum of the first n entries in an array of integers). Prove that the function is correct, or explain why it does not produce correct results. ArraySumA(integers n, a[1], a[2], … , a[n]) Local variables: integers i, j     i = 0     j = 0     while i ≤ n do         i = i +...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
Read each question carefully. Write your response in the space provided for each part of each...
Read each question carefully. Write your response in the space provided for each part of each question. Answers must be written out in paragraph form. Outlines, bulleted lists, or diagrams alone are not acceptable and will not be scored. Atherosclerosis is a disease that results when certain cells and proteins of an individual’s body adhere to and damage blood vessels, especially those around the heart. Researchers continue to look for improved ways to treat individuals with the disease. Data obtained...
Multiple Choice Questions \Indicate the best answer in the space provided 1. The difference between regulations...
Multiple Choice Questions \Indicate the best answer in the space provided 1. The difference between regulations and revenue rulings is that _____ a. Revenue rulings are not limited to a given set of facts and regulations are limited b. Revenue rulings are the direct law-making powers of Congress and regulations are not c. Revenue rulings require approval by the Secretary of the Treasury; regulations do not d. Revenue rulings do not have the authority of regulations; regulations are a direct...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue...
QUESTION 1 What does the following code segment output? int red, blue; red = 7; blue = red + 2 * 5 red++; blue = blue + red; cout << blue; 4 points    QUESTION 2 Is the following statement true or false? The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values: int x; if (x >=...
Please answer the following C question: Read the following files called array-utils5A.c and array-utils5A.h. Build an...
Please answer the following C question: Read the following files called array-utils5A.c and array-utils5A.h. Build an executable with gcc -Wall -DUNIT_TESTS=1 array-utils5A.c The definitions for is_reverse_sorted and all_different are both defective. Rewrite the definitions so that they are correct. The definition for is_alternating is missing. Write a correct definition for that function, and add unit tests for it, using the unit tests for is_reverse_sorted and all_different as models. Please explain the logic errors present in in the definition of is_reverse_sorted...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT