Please explain clearly your answers (step by step):
1) What is the output of the following code snippet?
int my_fun (int A[], int size)
{
int result = 0;
for (int i = 0; i < size; i++)
{
result = result + A[i];
}
return result;
}
int main()
{
int myarr[10] = { 5, 6, 10, 1, 2, 4, 8, 1, 2, 1 };
for (int i = 0; i < 3; i++)
{
cout << my_fun(myarr, i);
}
}
2) What is the output of the following code snippet?
int my_fun(int A[], int size)
{
int result = 0;
for (int i = 0; i < size; i++)
{
result = result + A[i];
}
return result;
}
int main()
{
int myarr[10] = { 2, 4, 10, 1, 2, 4, 8, 1, 2, 1 };
for (int i = 0; i < 3; i++)
{
cout << my_fun(myarr, myarr[i]);
}
}
3) Consider the following code snippet:
int cnt = 0;
int numarray[2][3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
numarray[j][i] = cnt;
cnt++;
}
}
What is the value of numarray[1][2] after the code snippet is executed?
4) Consider the following code snippet:
int cnt = 0;
int myarray[4][5];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 4; j++)
{
myarray[j][i] = cnt;
cnt++;
}
}
What is the value of myarray[1][2] after the code snippet is executed?
1)answer)0511
Given myarr is
5 6 10 1 2 4 8 1 2 1
Loop 0
Sending myarr with size 0 to function my_fun
in my_fun we find the sum of elements in given array
Array A[] in my_fun is
my_fun return value 0
Loop 1
Sending myarr with size 1 to function my_fun
in my_fun we find the sum of elements in given array
Array A[] in my_fun is
5
my_fun return value 5
Loop 2
Sending myarr with size 2 to function my_fun
in my_fun we find the sum of elements in given array
Array A[] in my_fun is
5
6
my_fun return value 11
2)answer)61735
Given myarr is
2 4 10 1 2 4 8 1 2 1
Loop 0
Sending myarr with size 2 to function my_fun
in my_fun we find the sum of elements in given array
Array A[] in my_fun is
2
4
my_fun reutn value 6
Loop 1
Sending myarr with size 4 to function my_fun
in my_fun we find the sum of elements in given array
Array A[] in my_fun is
2
4
10
1
my_fun reutn value 17
Loop 2
Sending myarr with size 10 to function my_fun
in my_fun we find the sum of elements in given array
Array A[] in my_fun is
2
4
10
1
2
4
8
1
2
1
my_fun reutn value 35
3)answer)5
numarray is
0 2 4
1 3 5
element at 1 row and 2 column is 5
4)answer)9
myarray is
0 4 8 12
16
1 5 9 13
17
2 6 10 14
18
3 7 11 15
19
element at 1 row and 2 column is 9
Please explain clearly your answers (step by step): 1) What is the output of the following...
Please, explain your answer clearly (step-by-step) What output does this loop generate? int j = 1; do { int value = j * 2; j++; cout << value << ", "; } while (j <= 5); What is the output of the following code snippet? int my_fun (int A[], int size) { int result = 0; for (int i = 0; i < size; i++) { result = result + A[i]; } return result; } int main() { int...
Please, explain clearly each line of code with your answers. Question 1 Consider the following code snippet: int ctr = 0; int myarray[3]; for (int i = 0; i < 3; i++) { myarray[i] = ctr; ctr = ctr + i; } cout << myarray[2]; What is the output of the code snippet? Question 2 Consider the following code snippet: int cnt = 0; int numarray[2][3]; for (int i = 0; i < 3; i++) { for (int j =...
1.The following statement gets an element from position 4 in an array named myArray: x = myArray[4]; What is the equivalent operation using an array list named list.? A x = list.get(); B x = list.get(4); C x = list.get[4]; D x = list[4]; 2.Consider the following code snippet: ArrayList<Integer> num1 = new ArrayList<Integer>(); int data; Scanner in = new Scanner(System.in); for (int i = 0; i < 5; i++) { data = in.nextInt(); num1.add(data); if (data == 0 &&...
QUESTION 9 What will be the output of following code snippet? int a[3] = {1, 2, 3}; int *p = a; int **r = &p; printf("%p %p", *r, a); A. Different memory addresses printed B. 1 2 C. Same memory address printed twice D. 1 1 2 points QUESTION 10 What will be the output of following code snippet? int arr[4] = {1, 2, 3, 4}; int *p; p = arr + 3; *p = 5; printf("%d\n", arr[3]); A....
What is the output of the following code snippet? (If there is some kind of syntax error indicate this by marking "error" in your answer choice) 1. int laps = 8; if (laps++ > --laps) laps += 2; else if (--laps > (laps - 1)) laps += 4; else if (++laps) laps -= 3; cout << laps << endl; 2. What is the output of the following code snippet? int j = 47; int i = 8; j =...
Language is C++ Complete the following Review Questions: 1. This is a control structure that repeats a group of statements in a program? a. loop b. switch c. main() function d. compiler 2. In the expression number++,the ++operator is in what mode? a. Prefix b. Pretest c. Postfix d. Posttest 3.This is a variable that controls the number of iterations performed by a loop. a. Loop control variable b. Accumulator c. Iteration register variable d. Repetition meter 4. The do-whileloop...
QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...
Please try to explain the answers as well. It will be highly appreciated. Output of the following expression: 5 * 4 % 2 = ? Output of a loop: Example: What will be the output of the Java code (Assume all variables are properly declared.) num = 10; while (num <= 32) num = num + 5; System.out.println(num); What will be the output of the Java code (Assume all variables are properly declared.) public class test { ...
C++, Will Upvote: A) Try to get the following programs to run in your environment. B) If the programs will run, document each line of code with comments and describe any changes you had to make to the original code to get it to work. If the programs are unable to be modified to run with desirable results, explain why you think so. C) Description your solution and a synopsis of how your code is intended to work and the...
1)What is the output of the following code: int i = 10; do { cout << i; i++; } while (i < 5); cout << "-done"; 2)What is the output of the following code (note there are no endl's, all output is on single line)? for (int i = 1; i <= 3; i++) { cout << '('; for (int j = 0; j < (i*2); j++) cout << 'x'; cout << ')'; }