Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

SBT | JULY 14 | DAILY TEST

 TECHNICAL MCQ


1.

What should be the output of the following program?
#include <stdio.h>
int main() {
int i,j;
for (i=0; i<5; i++) {
for (j=0; j<=i; j++) {
printf(" * ");
}
printf("\n");
}
return 0;
}


ans : c


2.

Predict the output of the below program:
#include <stdio.h>
#define EVEN 0
#define ODD 1
int main()
{
int i = 3;
switch (i & 1)
{
case EVEN: printf("Even");
break;
case ODD: printf("Odd");
break;
default: printf("Default");
}
return 0;
}
 

ans : odd

 

 

3.

Which of the following is not a part of Execution Flow during debugging?
Step Over
Step Into
Step Up
Step Ou

 

 

4.

What is true about a break?
Break stops the execution of entire program
Break halts the execution and forces the control out of the loop
Break forces the control out of the loop and starts the execution of next iteration
Break halts the execution of the loop for certain time frame

 


 5.

Software mistakes during coding are known as
errors
failures
bugs
defects
 

 

6.

Find out the error, if any in the below program?
#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
case 1:
printf("Case1");
break;
case 1*2+2:
printf("Case2");
break;
}
return 0;
}
 

No error

 

 

7.

Effective testing will reduce ___ cost.
maintenance
design
coding
documentation

 

 

8.

Cyclomatic Complexity method comes under which testing method.
Yellow box
White box
Gray box
Black box

 

 

9.

What is testing process first goal?
Bug prevention
Testing
Execution
Analyses
 

 

10.

Which of the following is the way of ensuring that the tests are actually testing code?
Control structure testing
Complex path testing
Code coverage
Quality assurance of software
 

 

 -------------------------------------------------------------------------------------------------------------------------

 

PROGRAMMING 

 

 

1.

Problem statement

There are N Homeless people in the community and N houses in the community. It will be given in the
array (people) , height of the person and in the array house capacity of the house is given.
Government decided to give homes for people on the basis of following conditions:
Priority is given for the people from left to right of the array Each person is allotted to a house if and
only if the capacity of house is greater than or equal to persons height Nearby empty Houses are
alloted to the person( starting from extreme left) You need to find the number of homeless people who
have not allotted any home if the government follows the above conditions.So that government will
have an idea for how many people they need to allot home for next time.
Input Format
The first line contains an integer, N, denoting the number of people and number of houses. Each line i
of the N subsequent lines (where 0 <= i <= N) contains an integer describing peoplei. Each line i of the N
subsequent lines (where 0 <= i <= N) contains an integer describing housei.
Constraints
1 <= N <= 10^3
1 <= peoplei <= 10^5
1 <= housei <= 10^5
Output Format
As mentioned in the problem statement.
For example in first sample test cases:-
people=3,8,5 house=1,9,4 people0=3 can fit in 9 which is nearest from left in array house people1=8
cannot fit in any home which is left (i.e, 1 and 4) people2=5 cannot fit in any home which is left (i.e, 1
and 4) So return 2,which is number of homeless people


 PYTHON CODE :

N=int(input())
people=[]
house=[]
#to read data of people and house arrays
for i in range(N): people.append(int(input()))
for i in range(N): house.append(int(input()))
count=0
for i in range(N):
    for j in range(N):
        if(people[i]<house[j]):
            count+=1
            house[j]=-1
            break
print(N-count)

 

 

2.

Problem statement

Little Robert likes mathematics. Today his teacher has given him two integers and asked to find out
how many integers can divide both the numbers. Would you like to help him in completing his school
assignment?
Input Format
There are two integers, a and b as input to the program.
Constraints
Output Format
Print the number of common factors of a and b.
 

 

PYTHON CODE :

data  = input()
li = data.split()
 
a = int(li[0])
b = int(li[1])
 
def gcd(a, b):
    if (a == 0):
        return b;
    return gcd(b%a, a);
 
if (a>0 and a<(10**12+1) and b>=1 and b<(10**12+1)):
    count = 1
    for i in range(2, gcd(a, b)+1):
        if a%i==0 and b%i==0:
            count = count+1
    print(count)

 

 

 

3.

Problem Statement

In an airport , the Airport authority decides to charge some minimum amount to the passengers who
are carrying luggage with them. They set a threshold weight value, say T, if the luggage exceeds the
weight threshold you should pay double the base amount. If it is less than or equal to threshold then
you have to pay $1 which is the base amount.
Input Format
The first line contains an integer, N, denoting the number of luggages. Each line i of the N subsequent
lines (where 0 <= i)
Constraints
1 <= N <= 10^5
1 <= weightsi <= 10^5
1 <= T <= 10^5
Output Format
As mentioned in the problem statement 


PYTHON CODE :

def weightMachine(N,weights,T):
    amount=0
    for i in weights:
        amount+=1
        if(i>T):
            amount+=1
    return amount
N=int(input())
weights=[]
for i in range(N):
    weights.append(int(input()))
T=int(input())
print(weightMachine(N,weights,T))

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 


Post a Comment

Previous Post Next Post