The document is the description of an informatics competition called ELEKTRIJADA 2007 held in Čanj, Serbia from May 14-19, 2007. It contains 10 multiple choice questions about C programming concepts and outputs of code snippets.
The document is the description of an informatics competition called ELEKTRIJADA 2007 held in Čanj, Serbia from May 14-19, 2007. It contains 10 multiple choice questions about C programming concepts and outputs of code snippets.
T TO OT TA AL L ELEKTRIJADA 2007 INFORMATICS, anj, May 14-19. 2007. O What's the output of the next program? Put exactly one character in one box, just as will be displayed on the screen.
#i ncl ude <st di o. h> mai n( ) { i nt k=0; st r uct enkoder { char f i : 4; char d: 1; unsi gned i nt k; } t = { 0, 127 , 0};
f or ( t . d=- - t . f i ; t . f i ; t . f i +=t . d, t . k++ ) ; pr i nt f ( " %d\ n" , t . k) ; f or ( t . d=- - t . f i ; t . f i ; t . f i - =t . d, t . k++ ) ; pr i nt f ( " %d" , t . k) ; } Output:
O What's the output of the next program?
#i ncl ude <st di o. h>
i nt ni z[ 5000] , n;
voi d f s( i nt n) { f or ( ; n ; ni z[ n] = n- - ) ; }
voi d f r ( i nt s) { i nt i , j , k, t i =s, t n=n; whi l e( t n>1) { f or ( i =s; ni z[ i ] ; i +=2) ni z[ i ] =0; s = ( ni z[ i - 1] ) ? 1 : 2; f or ( i =1; i <=t n; i ++) i f ( ! ni z[ i ] ) { f or ( j =i ; j <t n; j ++) ni z[ j ] =ni z[ j +1] ; ni z[ j ] =0; t n- - ; } } pr i nt f ( " %d\ n" , ni z[ 1] ) ; }
i nt mai n( ) { f s( n=10) ; f r ( 1) ; f s( n=1000) ; f r ( 2) ; } Output:
O What's the output of the next program? Suppose that a Floating Point data is represented by ussually used FP standard IEEE 754. Suppose that an integer data (int) is 32 bits wide. #i ncl ude <st di o. h> #def i ne M 0xFF800000 uni on uf i { f l oat f ; i nt i ; } f i ; mai n( ) { i nt i , f i i , s; f or ( f i . f =1; f i . f <4; f i . f *=2) { f or ( f i i =~( f i . i | M) ; f i i &1; f i i >>=1, s++) ; f or ( f i i =( f i . i &M) ; ! ( f i i &1) ; f i i >>=1, s- - ) ; pr i nt f ( " %d\ n" , f i i ) ; } } Output:
O What's the output of the next program?
#i ncl ude <st di o. h> i nt i , ni z[ 7] ; i nt f f ( i nt n) { i nt x0=0, y0=1, x1=1, y1=n, a, b, br =0; do { a=( y0+n) / y1*x1- x0; b=( y0+n) / y1*y1- y0; x0=x1; x1=a; y0=y1; y1=b; br ++; } whi l e ( x0<y0) ; r et ur n ( br ) ; } i nt f m1( i nt *n, i nt nn) { i nt i , j ; f or ( i =j =1; j <nn ; j ++) i f ( ( *( n+j ) - *( n+j - 1) ) >( *( n+i ) - *( n+i - 1) ) ) i =j ; r et ur n ( i ) ; } i nt f m2( i nt *n, i nt nn) { i nt i , j ; f or ( i =j =1; j <nn ; j ++) i f ( ( *( n+j ) - *( n+j - 1) ) <( *( n+i ) - *( n+i - 1) ) ) i =j ; r et ur n ( i ) ; } mai n( ) { f or ( i =1; i <=5; ni z[ i - 1] =f f ( i ) , i ++) ; pr i nt f ( " %d\ n" , ni z[ f m1( ni z, 7) ] ) ; pr i nt f ( " %d" , ni z[ f m2( ni z, 7) ] ) ; } Output:
ELEKTRIJADA 2007 INFORMATICS, anj, May 14-19. 2007. O What's the output of the next program?
#i ncl ude <st di o. h> t ypedef i nt ( *i 2i ) ( i nt ) ;
i nt f 1( i nt x) { r et ur n ( ++x) ; } i nt f 2( i nt x) { r et ur n ( - - x) ; }
i nt t ( i 2i f 1, i nt x) { r et ur n ( f 1( f 1( x) ) ) ; }
mai n( ) { pr i nt f ( " %d\ n" , t ( f 1, t ( f 1, f 2( 10) ) ) ) ; pr i nt f ( " %d\ n" , t ( f 2, t ( f 2, f 1( 10) ) ) ) ; } Output:
voi d i ni t ( ) { i nt i ; f or ( i =1; i <020; pr i nt f ( " %x " , *( pc+i ++) ) ) ; pr i nt f ( " %x\ n" , pc) ; }
voi d pr i nt ( ) { pr i nt f ( " %o\ n%o" , **ppc, **ppd%0x100) ; }
mai n( ) { i ni t ( ) ; pr i nt ( ) ; }
Suppose that the next figure shows screen after the function call init():
Find the output of function call print(). Output:
O What's the output of the next program?
#i ncl ude <st di o. h> #def i ne M( T, X, Y) {T a=X/ Y; y+=a+++x; f ( n- 1) ; } i nt i =3, y, x; voi d f ( i nt n) { i f ( n) { M( i nt , ++x, ++y) M( i nt , x, y) M( i nt , x++, y++) } } mai n( ) { f or ( ; i - - >1 ; f ( i ) , pr i nt f ( " %d\ n" , y) ) ; } Output:
O What's the output of the next program?
#i ncl ude <st di o. h>
#def i ne S( t , m, n) {t p=m; m=n; n=p; b++; }
i nt b;
voi d f sj ( i nt d, i nt g, i nt a[ ] ) { i nt i , j ; i f ( d>=g) r et ur n; i f ( d==g- 1) { i f ( a[ d] >a[ g] ) S( i nt , a[ d] , a[ g] ) ; r et ur n; } f or ( i =d, j =g; i <j ; i ++, j - - ) i f ( a[ i ] >a[ j ] ) S( i nt , a[ i ] , a[ j ] ) ; f sj ( j , g, a) ; f or ( j - - ; j >=d; j - - ) f or ( i =j ; a[ i ] >a[ i +1] ; i ++) S( i nt , a[ i ] , a[ i +1] ) ; }
mai n( ) { i nt ni z[ 100] ; i nt i ; f or ( i =100; i ; ni z[ 100- i ] =i , i - - ) ; f sj ( 0, 99, ni z) ; pr i nt f ( " %d" , b) ; }
Output:
40 0 0 10 30 40 0 14 30 40 0 11 30 40 0 403010 ELEKTRIJADA 2007 INFORMATICS, anj, May 14-19. 2007. O What's the output of the next program? #i ncl ude <st di o. h> voi d f si ( char s[ ] , i nt b[ ] ) { i nt i , j ; f or ( i =0; i <10; b[ i ] =0, i ++) ; f or ( i =0; s[ i ] ! =0; i ++) ; f or ( i - - , j =0 ; i >=0; b[ j ] =s[ i ] - ' 0' , i - - , j ++) ; } i nt f l ( i nt n1[ ] , i nt n2[ ] , i nt k) { i nt i ; f or ( i =9; i >0; i - - ) { i f ( n1[ i ] <n2[ i ] ) r et ur n 1; el se i f ( n1[ i ] >n2[ i ] ) r et ur n 0; } r et ur n ( k ? n1[ 0] <n2[ 0] : n1[ 0] <=n2[ 0] ) ; } voi d f d( i nt n[ ] ) { i nt i , p, t ; f or ( p=0, i =0; i <9; i ++) { t =n[ i ] *2; n[ i ] =t %10 + p; p=t / 10; } } voi d f p( i nt n[ ] ) { i nt i , p, t ; f or ( p=0, i =9; i >=0; i - - ) { t = p*10 + n[ i ] ; n[ i ] =t / 2; p=t %2; } } voi d f m( i nt n1[ ] , i nt n2[ ] , i nt r ez[ ] ) { i nt i , j , p; f or ( i =0; i <=9; i ++) { i f ( n2[ i ] <=n1[ i ] ) r ez[ i ] =n1[ i ] - n2[ i ] ; el se { j =i +1; do { p=0; n1[ j ] - - ; i f ( n1[ j ] ==- 1) { n1[ j ] =9; j ++; p=1; } } whi l e ( p) ; r ez[ i ] =10+n1[ i ] - n2[ i ] ; } } } i nt mai n( ) { char ns1[ 10] =" 10" , ns2[ 10] =" 1000" ; i nt i , s; f or ( s=2; s; s- - ) { i nt n[ 10] ={0}, p[ 10] ={2}, kod[ 10] ={0}; i f ( s==1) f si ( ns1, n) ; el se f si ( ns2, n) ; whi l e ( f l ( p, n, 1) ) f d( p) ; f p( p) ; f m( n, p, kod) ; f d( kod) ; f or ( i =9; ! kod[ i ] ; i - - ) ; f or ( ; i >=0; i - - ) pr i nt f ( " %d" , kod[ i ] ) ; pr i nt f ( " \ n" ) ; } } Output:
G What's the output of the next program?
#i ncl ude <st di o. h>
i nt f r a( char *s) { i nt i , b=0, k, kor , n; f or ( i =0; s[ i ] ; b+=kor , i ++) i f ( ( s[ i ] - ' a' ) %2) f or ( kor =5, k=0; k<( s[ i ] - ' a' ) / 2; k++) kor *=10; el se { f or ( kor =1, k=0; k<( s[ i ] - ' a' ) / 2; k++) kor *=10; kor *= ( s[ i +1] - s[ i ] >2) ? - 1 : 1; } r et ur n b; }
voi d f ar ( i nt b, char s[ ] ) { i nt i , c, k, bcs=0, d=1000; char sk[ 11] [ 5] = {" " , " a" , " aa" , " aaa" , " ab" , " b" , " ba" , " baa" , " baaa" , " ac" , " c" }; f or ( k=6; k>=0; k- =2) { f or ( i =0, c=b/ d; sk[ c] [ i ] ; i ++, bcs++) s[ bcs] =sk[ c] [ i ] +k; b%=d; d/ =10; } s[ bcs] =0; }
i nt mai n( ) { char s1[ 20] =" e" , s2[ 20] =" b" , s[ 20] =" " ; i nt op, p1=f r a( s1) , p2=f r a( s2) , r =0; f or ( op=1; op<3; op++) { swi t ch ( op) { case 1: r += p1/ p2; case 2: r += p1- p2; } f ar ( r , s) ; pr i nt f ( " %s\ n" , s) ; } }