0% found this document useful (0 votes)
51 views

Answers Solutions: Departments of Electrical & Computer Engineering "Introduction To Programming"

The document contains coding questions and answers for a programming exam. It lists 6 coding problems with multiple parts each that outputs results based on various loops, operators, and conditional statements. The student is asked to determine the outputs or complete code snippets to generate given outputs. The document provides identifying information for the student taking the exam and instructions that no outside materials are allowed.

Uploaded by

Mustafa Yılmaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Answers Solutions: Departments of Electrical & Computer Engineering "Introduction To Programming"

The document contains coding questions and answers for a programming exam. It lists 6 coding problems with multiple parts each that outputs results based on various loops, operators, and conditional statements. The student is asked to determine the outputs or complete code snippets to generate given outputs. The document provides identifying information for the student taking the exam and instructions that no outside materials are allowed.

Uploaded by

Mustafa Yılmaz
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Student Number: Answers

Name: Solutions
Osmangazi University, Faculty of Engineering & Architecture
Departments of Electrical & Computer Engineering Introduction to Programming

1. Determine the outputs of the following code.


a) int i; for(i=4;i>-2;i-=2) printf("%d ",i);
4 2 0

b) long a=37; printf("%d ",((a>>2)+1)|1);


11

c) double x=1.12;
while(x<4.5)
{ printf("-%1.0f",x); x*=2; }
-1-2-4

d) int i=0,k=2;
for(;i<6;++i)
do{
printf("%d%d",k,i); i++;k++;
} while(k<5);
20314254

e) int i=37,k=0x1A;
if(i&k) printf("%d",i&k);
else printf("%d",i|k);
63
f) int i=37,k=4;
printf("%d",i/k+i%k);
10

Note: No books,, notes, calculators etc. allowed. 60 minutes.

05.12.2006
2nd midterm

Student Number: Answers


Name: Solutions
Osmangazi University, Faculty of Engineering & Architecture
Departments of Electrical & Computer Engineering Introduction to Programming

05.12.2006
2nd midterm

2. Some code is removed in the following code. Complete the lines in order to generate the
outputs given.
a) int i;
for(i=11;i>0;i-=2)
printf("%d ",i);
output: 11 9 7 5 3 1
b) int a=32,b=2,c=3;
switch(b+c*2){break;
case 2: printf("%d",a);
case 4: printf("%d",b);break;
case 8: printf("%d",c);
default: printf"%d",b);
}
output: 32
c) int a=1,b=2,c=3,k;
do{
if(a+b==c)
printf("23");
if(k=c*a-b-1)
printf("235");
else
printf("%d4",b+c);
} while(b<0);
output: 2354
d) int i=0;
while(1){
print("%d ",i+2);
if(i>=6) break;
i++;
}
output: 2 3 4 5 6 7 8

Note: No books,, notes, calculators etc. allowed. 60 minutes.

You might also like