Answers Solutions: Departments of Electrical & Computer Engineering "Introduction To Programming"
Answers Solutions: Departments of Electrical & Computer Engineering "Introduction To Programming"
Name: Solutions
Osmangazi University, Faculty of Engineering & Architecture
Departments of Electrical & Computer Engineering Introduction to Programming
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
05.12.2006
2nd midterm
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