int a[5];
a[4] = 3;
for (int i=3; i >= 0; i--) {
a[i] = 2*a[i+1] - i;
cout << a[i]; }
int arr[] = {1,4, 1, 0); for (int i=0; i < 4; ++i) cout<<arr[i]*2; 0140 1014 1410 (space in between each number) 1410 None of the above void square(int &n){n= n*n;} int arr[] = {1, 2, 3}; int number = 4; Which of the following function calls are acceptable? square(1); square(arr[number]); square(number); square(2);
what is the output of the following code segment? C++ g. int arr[3][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) arr[i][j] =i*4 + j; for (int i = 0; i < 3; i++) for (int j = 0; j < 4; j++) cout << arr[i][j] << " "; h. int next(int & x) { x= x + 1; return (x + 1); int main() { int y = 10;...
#include<iostream> using namespace std; double hey(int x){ if(x==2) return 1; int i=0; if (x%2==0){ while(i<=2){ cout<<(x/2)<<endl; i++; break; } } if (x%2==1){ while(i<=2){ i=3*x+1; cout<<i<<endl; } return 1; } } int main() { int n; cout<<"insert a number to check how many steps to reduce down to 2"<<endl; cin>>n; cout<<hey(n)<<endl; return 0; } I couldn't
Consider the following array: int a[] = { 1, 2, 3, 4, 5, 4, 3, 2, 1, ?); What are the contents of the array a after the following loops complete? a. for (int 1-1; 1 < 10; i++ ) { a[i] a[1-1]; } b. for (int i 9; i > 0; i--) a[i]-ali 1 c. for (int i 0; i <9; it+) a[i]ai ; H e. for (int i-1; i <10; i+) aliaiai 1; h f. for (int i...
(a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0) return 0; 3 return (n-1 + g(n-1)); 4} (b) Consider the following C++ function: 1 bool Function (const vector <int >& a) { 2 for (int i = 0; i < a. size ()-1; i ++) { 3 for (int j = i +1; j < a. size (); j ++) { 4 if (a[i] == a[j]) return false; 5 6 } 7 return...
Consider the following C++ code segment: for (int i = 0; i <n; ++i) { for (int j = 0; j <m; ++j) if (i != j) cout << "0"; else cout << "1"; } } Which of the options below gives the correct output if the value of nis 2and the value of mis 3? 1. 100010 2. 011101 3. 100100 4. 010001
in c++ #include <iostream> using namespace std; int main() int beta[7] = 3, 5); for (int i = 2; i < 7; i++) beta[i] = 3 * i + 2; beta[i - 1] = beta[i - 1] + beta[i]; beta[i - 2) = betali - 2] + beta (i - 1]; for (int i = 0; i < 7; i++) cout << beta[i] << " "; cout << endl; return 0;
QUESTION Z What is the output of the following code: int list[] = {1, 2, 3, 4, 5, 6}; for (int i = 1; i < 6; i++) list[i] = list[i - 1]; for (int i = 0; i < 6; i++) cout << list[i] << ""; 0 1 2 3 4 5 6 0 2345 61 0 111111 0 234 566
Question 5: A) Consider: int i=1; int fun(int x) { for(int i=0; i<4; i++) { x += i; return x; What value is returned by a function call fun(1)? B In C, static variables can only be initialized by literals, not functions. For example, this is allowed: static int x = 5; But this is not allowed: static int x = compute_initial(); Why would this be the case? A Because you can never initialize a variable using a function, even...
or (int i - 3; i<ll; i-i+2) Solution: cout< iend; i-i2 B) What will the following program fragment output? (2 points) int mainc int j 7, d 2; double sum 0; 5 Solution: sumd; --ji 9 10 cout<esum; 12 13