Overnight Programming Challenge
6th-7th October 2012
4:30 p.m.-2:30p.m.
Submit your answers on blog.utkarsh@gmail.com or to any utkarsh member before 2.30p.m. on 7th October 2012
SECTION 1 : CRACK
THE PATTERN - WRITE
AN ALGORITHM OR A PROGRAM IN C , C++
OR JAVA TO PRINT THE FOLLOWING PATTERNS
(5 marks each)
1.
4 3
2 1 2
3 4
3
2 1 2 3
2
1 2
1
2
1 2
3
2 1 2 3
4 3
2 1 2
3 4
2.
4
3 2 1 2 3 4
3
3 2 1 2 3 3
2
2 2 1 2 2 2
1 1 1 1 1 1 1
2 2 2 1 2 2 2
3 3 2 1 2 3 3
4 3 2 1 2 3 4
3.
1
2 3 4
5
6
7
8
9 10
11 12 13
14
15
16
4.
1 2
3 4 5
16 17 18
19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
SECTION 2 : FIND THE OUTPUT
(5 marks each)
5.
#include
void main()
{
static char *a[]={"happy","birthday","mahatma","gandhi"};
char **1[]={a+3,a+2,a+1,a},***z;
z=1;
++z;
printf("%s",**z+1);
}
A. ahatma B. appy
C. mahatma D. irthday
6.
#include
struct mybox{int length,breadth,height;
}
void dimension(mybox m)
{printf("%d x %d x %d",m.length,m.breadth,m.height);
printf("\n");
}
void main()
{
mybox b1={10,15,5},b2,b3;
++b1.height;
dimension(b1);
b3=b1;
++b3.length;
b3.breadth++;
dimension(b3);
b2=b3;
b2.height+=5;
b2.length--;
dimension(b2)
}
7. class
q16{
public
static void main(String args[]){
int
count=0;
for(int
i=0;i<3 i="i" span="span">
3>
for(int
j=0;j<4 j="j" o:p="o:p">4>
for(int k =0;k<5 k="k" o:p="o:p">5>
++count;
if(i==1
&& j==2 && k==3) break resume;
}
System.out.println(“\tcount=”+count);
}
}
}
8. int
i=0;
outer:
while(true)
{
i++;
inner:
for(int
j=0;j<10 j="j" o:p="o:p">10>
i+=j;
if(j==3)
continue
inner;
break
outer;
}
continue
outer;
}
System.out.println(i);
SECTION 3:
WHATZ THE ERROR?-PREDICT THE
ERROR PRODUCED BY THE FOLLOWING CODE
(5 marks)
9. public
class While{
public void loop( ){
int x=0;
while(1){System.out.print(“x
plus one is”+(x+1));
}
}
SECTION 4: THE BIG QUESTION
(10 marks)
10. A bank intends to design a program to display the denomination of an input amount upto 5 digits. The available denomination with the bank are of rupees 1000, 500, 100, 50, 20, 10, 5, 2 and 1.
Design a program to accept the amount from the user and display the break-up in descending order of denominations. (i.e. preference should be given to the highest denomination available) along with the total number of notes. [NOTE: only the denomination used should be displayed]
Also print the amount in words according to the digits.
EXAMPLE 1:
INPUT: 14856
OUTPUT: ONE FOUR EIGHT FIVE SIX
DENOMINATION:
1000 X 14 = 14000
500 X 1 = 500
100 X 3 = 300
50 X 1 = 50
5 X 1 = 5
1 X 1 =1
EXAMPLE 2:
INPUT: 235001
OUTPUT: INVALID AMOUNT