Wednesday 28 August 2013

SCAN IT Online Test Answer - Day 2 ( 28 / 8 /2013 )



                               SCAN IT Online Test - Answers

                            Day 2 – 28/8/2013 (Wednesday)


                              Multiple Choice Question


1. What will be the result for the following statement?

                      printf (“%d”, printf (“tifaccore”));

Solution:
The output is ‘tifaccore9’ , ‘tifaccore’ due to inner printf statement and 9 as length due to outer printf statement.


2. Initially the value of n is -54 , what will be the output generated for this program ?

if (n < 0)
{
        printf ("-");
        n = -n;
}

if (n % 10)
     printf ("%d", n);
else
     printf ("%d", n/10);

printf ("%d", n);

Solution:
      The output is -5454 . Here n%10 doesn’t affect n value.


3. What will happen if we execute the following code ?
int main(void)
{
      http://www.sastra.edu
     printf("SASTRA UNIVERSITY");
 
       return 0;
}

Solution:
The output is ‘SASTRA UNIVERSITY’ . The code will not affect because of http://www.sastra.edu . ‘http:’ will be considered as goto statement. ‘//www.sastra.edu’ will be assumed as comments and it will be ignored.



4. What will be output when you will execute following c code?
void main()
{
int check=2;
switch(check){
case 1: printf("Microsoft");
case 2: printf("Amazon");
case 3: printf("Ebay");
case 4: printf("Zoho");
default: printf("Wipro");
}
}

Solution:
The output is ‘Amazon Ebay Zoho Wipro’ . There is no break statement.



5. What will be output if you will compile and execute the following c code?
#define x 5+2
void main()
{
 int i;
i=x*x*x;
printf("%d",i);
}

Solution:
   The output is 5+2*5+2*5+2 è 27 .. “7*7*7” is a wrong approach.



6. What will be the output of the program?
int main()
{
int i=3;
switch(i)
{
case 1:
printf("Online Test");

case 2:
printf(“is");

case 3:
continue;

case 4:
printf("Boring");

default:
printf("Very Interesting");
}
return 0;
}

Solution:
It results in Compiler Error . We can use continue statement only for loop .. If we use loop inside switch that time we can use continue statement.


7. Which of the following structure declaration doesn’t require pass-by-reference?

a) struct{int a;}s;
main(){}

b) struct temp{int a;};
main(){
struct temp s;
}

c) struct temp{int a;};
main(){}
struct temp s;

d) None of the mentioned

Solution:
The answer is None of the mentioned.


8. What will be the output of the program?

int main()
{
int x=1, y=1;
for(; y; printf("%d %d", x, y))
{
y = x++ <= 5;
}
return 0;
}

Solution: 2 1 3 1 4 1 5 1 6 1 7 0

In the above program y value is 1 or 0.


9. What is the output for the following code ?

void main()
{
int a=10,b=20;
char x=1,y=0;
if(a,b,x,y)
{
printf("EXAM");
}
}

Solution: Nothing Will be printed.



10. What will be output when you will execute following c code?
void main()
{
int x=1;

switch(x<<2+x)
{
default:printf("Only");

case 4: printf("6 IT Students");

case 5: printf("got");

case 8: printf("Placed");
}
}

Solution:
 ” Placed”… It’s doing operation of left shift. And then checking the switch condition.


11. Consider the following declaration of enum.

(i)enum cricket {Sachin,Dhoni,Dravid}c;

(ii)enum cricket { Sachin,Dhoni,Dravid };

(iii)enum { Sachin,Dhoni=-5,Dravid }c;

(iv)enum c {Sachin,Dhoni,Dravid };

Choose the correct one.
Solution:: All Four are correct.


12. What will be the output of following code?
int main()
{
fun();
fun();
fun();
return 0;
}

void fun()
{
auto int i=0;
register int j=0;
static int k=0;
i++; j++; k++;
printf(“%d %d %d”,i,j,k);
}

Solution:
1 1 1 1 1 2 1 1 3 . In this problem , auto and register values will not change but in case of static variable , k is initialized only once across three calls of fun(). So the first time k outputs 1 then 2 then 3.


13. What will be output if you will compile and execute the following c code?
void main()
{
char *str="Hello world";
printf("%d",printf("%s",str));
}

Solution: Hello world11 .. Hello world for string and 11 for the length of that string.


14. What will be the output for the following snippet ?
void main()
{
int i=0;
for(;i<=2;)
printf(" %d",++i);
}

Solution: 1 2 3 . Each time ‘i’ value is incremented and it is printed.


15. Comment on the output of this C code?
struct temp
{
int a;
} s;


void change(struct temp);

main()
{
s.a = 10;
change(s);
printf("%d", s.a);
}

void change(struct temp s)
{
s.a = 1;
}

Solution: 10


16. What is the output of this C code?
void main()
{
int b = 5 & 4 | 6;
printf("%d", b);
}

Solution: 6 .



17. What will be output if you will compile and execute the following c code?
void main()
{
int i=4,x;
x=++i + ++i + ++i;
printf("%d",x);
}


Solution:

In Linux environment , it will print 19.
In Turbo C , it will print 21.
In JAVA , C# , it will print 18.



18. What is the output of the following code?
void main()
{
int s=0;
while(s++<10)
{
if(s<4 && s<9)
continue;
printf("%d",s);
}
}

Solution: 4 5 6 7 8 9 10


19. Find the output for the following.
int main()
{
int i = 1;
if (i++ && (i == 1))
printf("Tanjore");
else
printf("Trichy");
}
Solution: Trichy


20. How many times ‘SCAN IT’ will be printed in the following C program ?
main()
{
int a=0,b=5;
if(a=0) printf("SCAN IT ");
if(b=5) printf("SCAN IT ");
if((a>b)==1) printf("SCAN IT ");
printf("SCAN IT ");
}

Solution:
       2 times it will be printed. “ If(a=0)” result false so it won’t print . The reason is assigning a variable to zero is always returns 0 but in case of assigning a variable to other values , it will return 1.


                 Program Type Question

1. A number of “Cats” got together and decided to kill 999919 mice. Every cat killed equal number of “mice”. Write a program to find different possible number of cats.

Solution:
Logic : (999919 % x ==0) The value of x is from 0 to 999919. There may be different possible solution. For example the number of cats may be one , in that case 1 cat killed 999919 mice .. Assume there are 999919 cats , in that each cats killed 1 mice.. Using loop and the above if statement , you can write the code.


2. Write a C program to subtract two numbers without using subtraction operator.

Solution:

Logic : sum = a + ~b + 1; (~b is equivalent to –b-1)



3. Write a c program which takes password from users.

Sample output:
Enter the password:******
You have entered: scanit

Solution:

printf("Enter the password:");

while((p=getch())!= 13)
{
   password[i++] = p;
   printf("*");
}
password[i] = '\0';
printf("\nYou have entered: %s",password);


4. There are some goats and ducks in a farm. There are 60 eyes and 86 foot in total. Write a program to find number of goats and ducks in the farm.

Solution:

Logic : 2(x+y) = 60 so that x + y = 30 == > 1st Equation – eyes.
            4x + 2y = 86 . Solve the equation and get the value of x and y (i.e. Number of goats and ducks.)


5. Arun has a money pouch containing Rs.700. There are equal number of 25 paise coins, 50 paise and one rupee coins. Write a C program to find how many of each are there?

Solution:

             Logic x = 700 / (0.25+0.50+1);



                  Aptitude Questions.

1. You just bought TEN trees...
You want to plant them in FIVE rows with FOUR trees in each row.
How are you going to do it?

Solution:



2. Can you find the numbers A, B, C and D so that the following works?
A B C D x 4 = D C B A

Solution: A = 2 ; B = 1 ; C = 7 ; D =8. 2178 * 4 = 8712


3. An analog clock reads 3:15. What is the angle between the minute hand and hour hand ?
( The answer is not zero !)


Solution: At 3:15 , the hour hand will be ¼ of between 3 and 4 & the minute hand will be at 3.. The angle is ¼ of between 3 and 4. The total clock angle is 360. Half ( 12 to 6) is 180.. 180/6 will return angle between each number ( 2 and 3 , 3 and 4). SO the angle between 3 and 4 is 30 . ¼ of between 3 and 4 is 7.5..




4. How many times per day do a clock hands overlap ?
Solution:
22 Times Per day . The times are 12:00 1:05 , 2:11 , 3:16 , 4:22 , 5:27, 6:33, 7:38 ,8:44 , 9:49, 10:55.. 11 th hour not having any pair.



5.A is two years older than B who is twice as old as C. If the total of the ages of A, B and C be 27, the how old is B?A is two years older than B who is twice as old as C. If the total of the ages of A, B and C be 27, the how old is B?

Solution:
From the problem, A = B +2, B = 2 x C and A+B+C = 27
--> A + B + C = 27
--> (B + 2) + B + (B/2) = 27
--> 2B + 2 + (B/2) = 27
--> 2B + (B/2) = 25
--> 4B + B = 25 * 2
--> B = 10

0 comments:

Post a Comment