Sample questions

 
First round (Qualifying round)

1. A variable can have multiple storage classes. (T/F)

Ans: T

2. Size of int in C is always 2 bytes. (T/F)

Ans: F

3. main()
{
    char *str ="multi" "media";
    printf("%s",str);
}
(i) multi
(ii) media
(iii) multimedia
(iv) error

Ans: iii

4. main()
{
    int i=0;
    for(i=0;-i<10;++i)
      printf("%d",i);
}

(i) 0,1, 2 .... 10
(ii) infinite loop
(iii) abnormal program termination
(iv) 0,1,2....... 32767

Ans: iv

5. main()
{
    float i=1.1;
    double j=1.1;
    if(i==j)
      printf("Hello");
    else
      printf("Bye");
}
(i) Hello
(ii) Bye
(iii) HelloBye
(iv) error
 

Ans: ii

6. main()
{
    int i=0;
    while(+(+i--)!=0)
      i=i++;
    printf("%d",i);
}
(i) 0
(ii) -1
(iii) 1
(iv) error

Ans: ii

7. main()
{
    int i=0,j=1,k=-1,l;
    l=++i&&++j||++k;
    printf("%d %d %d %d",i,j,k,l);
}
(i) 1 2 -1 1
(ii) 0 1 -1 1
(iii) warning
(iv) error

Ans: i

8. struct a
{
    char c1;
    char c2;
    char c3;
    int i;
};
main()
{
    printf("%d",sizeof(struct a));
}
(i) 8
(ii) 16
(iii) 4
(iv) error

Ans: i

9.main()
{
    char a[5]="Sarmang";
    char *p;
    p=&a[5];
    for(i=0;*p;i++)
    {
      printf("%c",*(p+i));
      a++;
    }
}
(i) ng
(ii) Sarmang
(iii) warning
(iv) error

Ans: iv

10.main()
{
    int tnp(int n)
    {
      static int i=1;
      if(n>=5) return n;
      n=n+1;
      i++;
      return tnp(n);
   }
}

The value returned by tnp(1) is
(i) 2
(ii) 5
(iii) 4
(iv) error

Ans: iv
 

Multiple choice for these questions and answers will be displayed here on 5 Sep 2008.

 

Second round (Programming round)

Question:

N birds on a tree want to learn natural numbers. They start singing all natural numbers in the increasing order starting from 1. When a number K is sung, K birds fly away from the tree. If, at any second, the number of birds on the tree is strictly less than the number which must be sung, the birds restart the game and start singing the numbers from 1 again.

You are given an int ‘n’, the number of birds on the tree. Taking into account that singing a number takes exactly one second, return the total time elapsed before all birds fly away.

Constraints
- n will be between 1 and 10^5, inclusive.

Examples
0)
INPUT: 1

OUTPUT: 1
There is just one bird who flies at the first second.

 

1)
INPUT: 3

OUTPUT: 2
One bird flies away at the first second, the other two at the next one.

 

2)
INPUT: 4

OUTPUT: 3
At second 1, birds sing "one" and one of four birds flies away (with 3 birds remaining on the tree). At second 2, birds sing "two" and two of three birds fly away. At the third, the birds restart the game from 1 and the last bird flies away.

 

3)
INPUT: 14

OUTPUT: 7
During the first four seconds the birds will count from 1 to 4, so (1 + 2 + 3 + 4) = 10 birds will fly away, with 4 birds left on the tree. The game will be restarted from 1, so 1 and 2 birds will fly away on seconds 5 and 6 respectively. On second 7, the birds will restart the game again and the only remaining bird will fly away.

 

 

Organising Committee : Trainees of Sarmang Software