Sunteți pe pagina 1din 3

YEDITEPE UNIVERSITY

ES 112 – Algorithms and Programming, Summer 2010


MIDTERM I - 29/06/2010

1. (20 pts) Identify and correct the errors in each of the following statements.

a. printf( “The value is %d\n”, &number);

b. scanf( “%d%d”, &number1, number2 );

c. if ( c < 7 ) ;
printf( “ C is less than 7\n );

d. if ( c => 7 )
printf (“C is equal to or greater than 7 \n” );

2. (10 pts) What is the final value of x after performing the following operations?

int x = 21;
float y = 6;
float z = 14;
y = x / z;
x = 5.5 * y;

Answer: ______________

3. (10 pts) Consider the following program segment:

if ( i > 5 )
if ( j < 5 )
printf(“A”);
else
printf(“B”);
else
printf(“C”);

Determine the output from this segment if

i. i =7, j = 2 Answer: ______________

ii. i = 2, j = 7 Answer: ______________


4. (20 pts) Write a C program using while loop(s) that takes in one integer parameter and
depending on this parameter it produces an output. For example:

If you input 4:
It prints:
4 3 2 1 0 2 4 6 8
Or, if you input 7:
It prints:
7 6 5 4 3 2 1 0 2 4 6 8 10 12 14

5. (20 pts) Write a C program using while loop(s) that takes in one integer parameter and
depending on this parameter it produces an output. For example:
Girilen sayıya en yakın 5’in katı bulunup; 0’a kadar 5er 5er azalan sonrada bulunan sayının
10 katına kadar 10 ar 10 ar artan dizilimi yapan fonksiyon yazılacak…

If you input 8:
It prints:
10 5 0 10 20 30 40 50 60 70 80 90 100

Or, if you input 6:


It prints:
5 0 10 20 30 40 50

Or, if you input 13:


It prints:
15 10 5 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150

6. (20 pts) Write a C program that calculates and prints the sum of even integers from 22
to 300.

7. (20pts) Write a program that reads the user choice (from 1 to 10) and prints its channel
name description. The scala is as follows:

1&2: ShowTV
3: KanalD
4: TRT
5: FOX
6-10 : Digiturk

Notes:

 Give your answers on this sheet


 Duration 90 minutes
 No questions allowed
 Good luck.

S-ar putea să vă placă și