You are on page 1of 2

Question 1 (21%)

1. Which of the following is a valid variable name in C?


a. arithmetic average b. arithmetic.average c. arithmeticAverage d. arithmetic-average

2. Which of the folowing instructions has a different outcome on an integer variable x ?


a. x ––; b. x –= 1 c. x += –1; d. x = x - 1; e. x = 1 - x;

3. In which type of loop the execution of the first iteration is guaranteed regardless of the condition?
A. while B. do while C. for D. none of these

4. The condition of the control structure if( (x!= 20 && y > 30) || z == 25 ){...} would be
false when the values of the variables x, y and z are :
a. 10, 30, 15 b. 5, 10, 25 c. 15, 40, 30 d. 20, 30, 25 e. 25, 35, 15

5. What are the values of the varibles a, b, c after the following code fragment is executed?
...
int a = 5, b = 8, c;
c = 2*b - a;
if( a + b > c ){
c--;
a *= 2;
}else{
b -= c – 7;
}
a += a%3 + 4;
b--;
c = 3*(b+c);
...
a. 11, 3, 42 b. 15, 4, 42 c. 15, 7, 51 d. 11, 7, 54 e. 17, 3, 54

6. What is printed on the screen when the given code fragment is executed?
int c = 1, d = 5;
while( c <= d ){
c += 2 ;
d ++;
}
printf("%d %d", c, d);
a. 10 10 b. 11 10 c. 11 11 d. 13 12 e. None of these

7. After the following instrctions are executed, the array v would be:
...
int v[7] = {7, -2, 11, 4, -6, 10, 3};
v[1] = (v[2] + v[6])/2;
v[4] = 2*v[6] – v[3];
v[3] = 5 + v[1]*v[2];
v[6] = 2*v[2] + 3*v[3] + 4*v[4];

A. 4 -2 -3 -5 -6 -33 3 B. 4 -2 -9 -19 -6 20 3

C. 7 7 11 -9 2 10 10 D. 7 7 11 82 2 10 476
Question 2 (20%)
a. What will be the output printed on the screen if the user enters as input the number 10 ?
b. What does this program accomplish in general?
c. Implement the given program as a flowchart.
#include <iostream>
using namespace std;
int main(){
int n = 0, m, s = 0 ;
printf("Enter a natural number: ");
scanf("%d", &m);
while( n <= m ){
n += 2;
s += n;
printf("%d \n",n);
}
printf("%d",s);
return 0;
}

Question 3 (20%) a. Write a program in C which reads as input two decimal numbers and prints their
absolute values in descending order (largest to smallest).
For example if the user enters 2.5 -6.25 then the output must be 6.25 2.5
b. Solve the same problem using flowcharts.

Question 4 (19%) Write a program in C which reads as input a natural number n and 1
prints as result a triangle with numbers from 1 to n. For example, if the user enters as 12
input the number 5, the output should be: 123
1234
123 45

Question 5 (20%)Write a program that calculates sum of the numbers in the given positions.

Input specification
There will be 4 lines of data. You will be first given the size of the positions array (n). Then, the following
line will have n integers which is an ordered list in increasing order and 0 < n ≤ 3000. The third line will give
the size of the number array (m) where 0 < m ≤ 5000 and The last line will have m integers between -30000
and 30000.
Note: The positions start from 1 and goes until m.

Output specification
Show one integer number: Sum of the Numbers in the given Positions.

Sample Input I Sample Output I


5 62
2 5 7 9 10
10
1 8 7 5 17 15 6 7 19 12

You might also like