What is the value of n after this code runs?
1 Point
int n = 0;...
What is the value of n after this code runs?
1 Point
int n = 0;
int j = 7;
if ((j!=0) && (n < 25))
{
n = 1;
if (j > 4)
{
n = 2;
}
else
{
n = 3;
}
}
else
{
n = 4;
if (j%2 >= 2)
{
n = 5;
}
else
{
n = 6;
}
}
1. What will be the value of numbers[1] after the following code
is executed?
int[] numbers = {22, 33, 44};
for(int k = 0; k < 3; k++)
{
numbers[k] = numbers[k] + 5;
}
}
2. What will be the results of the following code?
final int ARRAY_SIZE = 5;
double[] x = new double[ARRAY_SIZE];
for(int i = 1; i <= ARRAY_SIZE; i++)
{
x[i] = 10.0;
}
3.What is the value of numbers [3] after the following line...
Consider the following function:
int counter( int n)
{ int s = 0;
for ( int i = 0; i < n; i++)
for
( int j = i; j > 0; j--)
s
= s + 1;
return s;
}
Part (a): How many times "s=s+1;" will be executed? Determine a
precise count. Show all your work.
Part (b): What is the time complexity of the "counter" function
in terms of Big-O notation? Justify and show all
your work.
int value = 1;
do
{
if (value % 2 == 0)
cout << value << " ";
value = value + 1;
}
while (value % 7 != 0);
cout << "\n" << value;
What will be displayed?
Consider the following C code that outlines Fibonacci
function
int fib (int n) {
if (n == 0) return 0;
else if (n==1) return 1;
else return fib(n-1) + fib (n-2);
}
For this programming assignment, write and test an ARMv8 program
to find Fibonacci (n).
You need to write a main function that calls the recursive fib
function and passes an argument n.
The function fib calls itself (recursively) twice to compute
fib(n-1) and fib (n-2). The input to...
// 1.
System.out.println("1.");
int max = 5;
for (int n = 1; n <= max; n++) {
System.out.println(n);
}
System.out.println();
// 2.
System.out.println("2.");
int total = 25;
for (int number = 1; number <= (total / 2); number++) {
total = total - number;
System.out.println(total + " " + number);
}
System.out.println();
// 3.
System.out.println("3.");
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 3; j++) {
for (int k = 1;...
In Java:
int[] A = new int[2];
A[0] = 0; A[1] = 2;
f(A[0],A[A[0]]);
void f(int x, int y) {
x = 1; y = 3;
}
For each of the following parameter-passing methods, saw what
the final values in the array A would be, after the call to f.
(There may be more than one correct answer.)
a. By value. b. By reference. c. By value-result.