Initial Evaluation Test, Introduction To Programming, 2017-2018

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Initial evaluation test, Introduction to programming, 2017-2018

1. What will be the output of the following code?


 int i=1,j=0,k=0,z=0;
 for (;i<=10;i++) while(j<=10) {j++; do { k++; z++; }while(k<=10); } cout<<z;

2. Is the next C++ code correct? If yes, what will it output? If not, why? (Explain)  
#include <iostream>
using namespace std;
void Sum(int y, int x, int& sum) {  x=2+x; y=3+x; sum=x+y; }
int main()
{ int a=2; int b=30; int c; Sum(5,5,c); cout<<c; Sum(3,b,c); cout<<c; return
0; }  

3. . Is the next C++ code correct? If yes, what will be the value of sum? If not, why? Explain.
int a[] = { 6, 4, 8, 3, 2, 5 }; unsigned int n=4; unsigned int i=1; int sum;
for (sum=10; i < n; ++i) sum -= *(a+i);

4. Which ones from the following code snippets set the variable found as 1, if and only if an element a is
found in the array x with n integers? Circle the right answers.

a. found =1; for (i=0; i<n; i++) if (x[i]!=a) found=0;


b. found=0; for (i=0; i<n; i++) if (x[i]==a) found=1;
c. for (i=0; i<n; i++) if (x[i]==a) found=1; else found=0;
d. found=0; for (i=0; i<n && ! found; ++i) if (x[i]==a) found=1;
e. found=1; i=0; while (i<n && found) if (x[i]==a) found =0; else i++;
f. found=i=0; while (i<n && !found) if (x[i]==a) found=1; else i++;
g. found=1; i=0; while (i<n && found) if (x[i]!=a) found=0; else i++;
h. found=1; for (i=0; i<n; i++) if (x[i]==a) found=0;

5. What will be the output of the following C++ code?


#include <iostream>
using namespace std;
int x=10,t;
char equal(int x, int y) { int a=1; t=t+x+y+a; return x+t==y?'N':'Y'; }
int main() { int y=2,z=3,t=1; cout<<t<<x<<y<<z;
if (equal(y,z)=='Y') cout<<"Yes"; else cout<<"NO"; cout<<t; return 0; }

6. What is the output of the following code?


int i,j,k,z=0;
for (i=1;i<=5;i++)
    z++;
for(j=i+1;j<=10;j++)
    z--;
for (k=j+1;k<=15;k++)
    z++;
cout<<z;

You might also like