Question

Questions on C++, I am not 100% sure on answers, so need to clarify. Simple explanation...

Questions on C++, I am not 100% sure on answers, so need to clarify. Simple explanation next to the question would be nice as well.

In mathematic notation, which is equivalent to the following statement when writing a

pseudocode?

x = 4y

A. x == 4y

B. x := 4y

C. x -> 4y

D. 4y = x

  1. Given the following pseudocode, the final value of x is __.

Start

int x = 5;

for i in 1 to 3 do

x = x + i

End

A. 5

B. 7

C. 9

D. 11

E. 13

  1. Given the following pseudocode, what will be the final output if m=24 and n=3?

r←m%n

while r !=0 do

m←n

n←r

r←m%n

return n

A. 3

B. 12

C. 6

D. 15

E. 8

  1. Given the following code segment, what is the total number of executions?

for (int i=1; i<17; i++)

{

cout << (5 / i) * 3;

}

A. 17

B. 18

C. 34

D. 36

  1. The following is an example of __ time complexity.

int findRemainder(int x, int y)

{

int r = x % y;

return r;

}

A. constant

B. linear

C. quadratic

D. exponential

E. logarithmic

  1. Given the following code segment, the total number of executions is __.

int x = 3;

int y = 4;

for i = 1 to n do

x = x + i

y = y - i

print x

print y

A. 2n

B. 4n + 2

C. 6n + 4

D. 8n + 6

E. 5n + 6

Homework Answers

Answer #1

Q1 Ans) B
   In pseudocode format, you can use = or := for assignment operation.

   Here in Given Options.
       A) x == 4y ; == is used for equality checking.
       B) x:= 4y ; := is an assignment operation(correct)
       C) x-> 4y ; -> denotes Replaced by
       D) 4y = x ; 4y is assigned to x

Q2 Ans) D
   Initially x is assigned to 5
   for i = 1 => x = x + 1 ; x= 5 + 1 = 6
   i = 2 => x = x + 2 ; x= 6 + 2 = 8
   i = 3 => x = x + 3 ; x= 8 + 3 = 11

Q3 Ans)A
  
   Initially, r = 24 % 3 = 0
   Since r == 0 it doesn’t enter into loop and returns simply n value. i.e,, 3

Q4 Ans) None of Them.
   The loop executes for i=1 to i=16 only. Since i<17 doesn’t iterate for i=17. The answer is 16.

Q5 Ans) A
   It just requires constant amount i.e,, O(1) time complexity as it just calculates the remainder.
  
   int findRemainder(int x, int y)
   {
       int r = x % y; -> O(1)
       return r; -> O(1)
   }

Q6 Ans) A
   The total number of statements are 2 and The loop executes for n times.
   So, it executes 2n times.

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
JAVA / I KNOW THERE IS MORE THAN ONE QUESTION BUT THEY ARE SO EASY FO...
JAVA / I KNOW THERE IS MORE THAN ONE QUESTION BUT THEY ARE SO EASY FO YOU I NEED YOUR HELP PLEASE HELP ME. I WILL GIVE UPVOTE AND GOOD COMMENT THANK YOU SO MUCH !!! QUESTION 1 What is the output after the code executes? Assume there are no syntax errors and the code will compile. int x = 10; do { System.out.println ( x ); x -= 3; } while (x > 0); A. 10 7 4 1...
C Programming I am trying to also print the frequency and the occurrence of an input...
C Programming I am trying to also print the frequency and the occurrence of an input text file. I got the occurrence to but cant get the frequency. Formula for frequency is "Occurrence / total input count", this is the percentage of occurrence. Can someone please help me to get the frequency to work. Code: int freq[26] = {0}; fgets(input1, 10000, (FILE*)MyFile); for(i=0; i< strlen(input); i++) { freq[input[i]-'a']++; count++; } printf("Text count = %d", count); printf("\n"); printf("Frequency of plain text\n");...
Why am I receiving different outputs when I run this code on visual studio and gcc...
Why am I receiving different outputs when I run this code on visual studio and gcc (unix)?. The correct output is -52. #define polyMacro(a, b) ((a * a) + (8 * a) + (3 * a * b) - (b * b)) int polyFunc(int a, int b) {    return ((a * a) + (8 * a) + (3 * a * b) - (b * b)); } int x = -7, y = 3; int x_copy = x, y_copy...
Answer the following questions: 1. Given the code segments below with n as the problem size,...
Answer the following questions: 1. Given the code segments below with n as the problem size, answer the following questions: //Code Segment 1 (Consider n as a power of 3) int sum = 0; for(int i = 1; i <= n; i = i*3) sum++;​​​​​​​// statement1 //Code Segment 2: (Consider both possibilities for x) if(x < 5){ for(int i = 1; i <= n; i++)    for(int k = 1; k <= i; k++)    sum++;​​​​​// statement2 } else{ for(int...
Hello! I hope you are healthy and well! I am hoping that this message finds you...
Hello! I hope you are healthy and well! I am hoping that this message finds you happy and content! I am having trouble solving this 5-part practice problem. I would greatly appreciate any and all help that you could lend! Thanks in advance! In the following proof, what is the justification for line 7? 1.     [(W ⊃ X) ⊃ Y] ∨ ( P ≡ Q) 2.     ∼X • ∼Y 3.     ∼(P ≡ Q) / ∴ ∼W 4.     ∼X                  2 Simp 5.     ∼Y                  2 Simp 6.     (W ⊃ X)...
1. Identify and correct the errors in each of the following statements: a) for (a =...
1. Identify and correct the errors in each of the following statements: a) for (a = 25, a <= 1, a--); {printf("%d\n", a);} b) The following code should print whether a given integer is odd or even: switch (value) {case (value % 2 == 0):puts("Even integer");case (value % 2 != 0):puts("Odd integer");} c) The following code should calculate incremented salary after 10 years: for (int year = 1; year <= 10; ++year) {double salary += salary * 0.05;}printf("%4u%21.2f\n", year, salary);...
d = int(input('Enter the date: ')) m = int(input('Enter the month: ')) y = int(input('Enter the...
d = int(input('Enter the date: ')) m = int(input('Enter the month: ')) y = int(input('Enter the year: ')) if m<3: m = m + 12 y = y - 1 a = (2*m) + (6*(m+1)/10) b = y + (y/4) + (y/400) - (y/100) c = d + a + b + 1 f = c / 7 if f == 0: print ('Sunday') elif f == 1: print ('Monday') elif f == 2: print ('Tuesday') elif f ==3: print...
In assembler code must be a gcd.s file So here is the C code I have...
In assembler code must be a gcd.s file So here is the C code I have written originally for the program. My question is how do I convert it to assembly code? //C code #include <stdio.h> int fibonacci(int n) { if(n <= 2) { return 1; } else { return fibonacci(n-1) + fibonacci(n-2); } } int main(void) { int n; printf("Enter Fibonacci term: "); scanf("%d", &n); printf("The %dth Fibonacci number is %d\n", n, fibonacci(n)); return 0; } Instructions In C...
In assembler code must be a gcd.s file So I here is the C code I...
In assembler code must be a gcd.s file So I here is the C code I have written originally for the program. My question is how do I convert it to assembly code? // C code below #include //this function swaps given integers void swap(int*a,int*b) {     int temp=*a;     *a=*b;     *b=temp; } //this function returns gcd of a and b int gcd(int a,int b) {     if(a     swap(&a,&b);     int r=a%b;     if(r==0)     return b;     return gcd(b,r); } int main() {     int first,second;     printf("Enter...
In Java please 10.9 Lab 6 In BlueJ, create a project called Lab6 Create a class...
In Java please 10.9 Lab 6 In BlueJ, create a project called Lab6 Create a class called LineSegment –Note: test changes as you go Copy the code for LineSegment given below into the class. Take a few minutes to understand what the class does. Besides the mutators and accessors, it has a method called print, that prints the end points of the line segment in the form: (x, y) to (x, y) You will have to write two methods in...