TECH-1
Pseudocodes + Advanced level of coding
QUESTION 1
What will be the output of the following pseudocode for x = 9, y = 7?
Integer fun(Integer x, Integer y)
Integer z
Set z = 2
y = y mod z
x = x mod z
return x + y
End function fun()
A. 17
B. 5
C. 2
D. -5
QUESTION 1
What will be the output of the following pseudocode for x = 9, y = 7?
Integer fun(Integer x, Integer y)
Integer z
Set z = 2
y = y mod z
x = x mod z
return x + y
End function fun()
A. 17
B. 5
C. 2
D. -5
C
QUESTION 2
What will be the output of the following pseudocode?
Integer p, q, r
Set p = 8, q = 6,r = 4
if(p > q)
p = q
Else
q = p
End if
if(r > q)
r = q
Else
q = r
End if
Print p + q + r
A. 13
B. 17
C. 14
D. 23
QUESTION 2
What will be the output of the following pseudocode?
Integer p, q, r
Set p = 8, q = 6,r = 4
if(p > q)
p = q
Else
q = p
End if
if(r > q)
r = q
Else
q = r
End if
Print p + q + r
C
A. 13
B. 17
C. 14
D. 23
QUESTION 3
What will be the output of the following pseudocode?
Integer e, f, g
Set e = 1, f = 1, g = 7
e = e + f
if(e + f)
if(f + (g ^ e))
e = 2
f = e
End if
End if
Print e + f + g
A. 11
B. 6
C. 12
D. 22
QUESTION 3
What will be the output of the following pseudocode?
Integer e, f, g
Set e = 1, f = 1, g = 7
e = e + f
if(e + f)
if(f + (g ^ e))
e = 2
f = e
End if
End if
Print e + f + g
A. 11
B. 6
C. 12
D. 22
A
QUESTION 4
What will be the output of the following pseudocode?
Integer pq, qr, rs, sp
Set pq=1, qr = 1
for (each rs from 0 to 2 )
for (each sp from -4 to -2 )
pq = pq + 2
if(pq > rs)
Continue
End if
pq = 1
if(pq > sp)
Jump out of the loop
End if
End for
End for
Print pq + qr
A. 13
B. 24
C. 35
D. 20
QUESTION 4
What will be the output of the following pseudocode?
Integer pq, qr, rs, sp
Set pq=1, qr = 1
for (each rs from 0 to 2 )
for (each sp from -4 to -2 )
pq = pq + 2
if(pq > rs)
Continue
End if
pq = 1
if(pq > sp)
Jump out of the loop
End if
End for
End for
Print pq + qr
D
A. 13
B. 24
C. 35
D. 20
QUESTION 5
What will be the output of the following pseudocode?
Integer x, y, z
Set y = 30, x = 10, z = 20
if (y > (z + x))
y = 1
else
x = x - 2
z = z - 2
End if
if (z > (y + x) || 1)
y = (0 ^ 5)
else
x = x + 2
z = x + 2
End if
Print x + y + z
A. 20
B. 24
C. 30
D. 31
QUESTION 5
What will be the output of the following pseudocode?
Integer x, y, z
Set y = 30, x = 10, z = 20
if (y > (z + x))
y = 1
else
x = x - 2
z = z - 2
End if
if (z > (y + x) || 1)
y = (0 ^ 5)
else
x = x + 2
z = x + 2
End if
Print x + y + z
D
A. 20
B. 24
C. 30
D. 31
QUESTION 6
What will be the output of the following pseudocode?
Integer var_ a = 50, var_ b = 23, var_ c
var_ c = var_ a + var_ b
var_ c = var_ c MOD var_ b
var_ b = var_ b + var_ c
var_ a = var_ a - var_ b
Print var_ a, var_ b, var_ c
A. 23 27 4
B. 23 17 3
C. 77 27 4
D. 69 19 4
QUESTION 6
What will be the output of the following pseudocode?
Integer var_ a = 50, var_ b = 23, var_ c
var_ c = var_ a + var_ b
var_ c = var_ c MOD var_ b
var_ b = var_ b + var_ c
var_ a = var_ a - var_ b
Print var_ a, var_ b, var_ c
A. 23 27 4
B. 23 17 3
C. 77 27 4
D. 69 19 4
A
QUESTION 7
What will be the output of the following pseudo code:
Integer _m
Set _m = 0
Integer _p[5] = {1, 1, 0, 1, 7}
if (_p[0] && _p[4])
_m = _p[1]
End if
if (_p[2] && _p[3])
_m = _p[2]
End if
Print _m
A. 18
B. 1
C. -5
D. 4
QUESTION 7
What will be the output of the following pseudo code:
Integer _m
Set _m = 0
Integer _p[5] = {1, 1, 0, 1, 7}
if (_p[0] && _p[4])
_m = _p[1]
End if
if (_p[2] && _p[3])
_m = _p[2]
End if
Print _m
A. 18
B. 1
C. -5
D. 4
B
QUESTION 8
What will be the output of the following pseudocode
Integer x, y, z, a
Set x=2, y=1, z=5
a=(x AND y) OR (z+1)
Print a
A. 2
B. 3
C. 5
D. 6
QUESTION 8
What will be the output of the following pseudocode
Integer x, y, z, a
Set x=2, y=1, z=5
a=(x AND y) OR (z+1)
Print a
A. 2
B. 3
C. 5
D. 6
D
QUESTION 9
What will be the output of the following pseudocode for input a = 30, b = 60, c = 90?
Integer a, b, c, sum
Read a, b, c.
Set sum = a + b + c.
if ((sum EQUALS 180) and (a NOT EQUALS 0) and (b NOT EQUALS 0) and (c NOT EQUALS 0))
print “Success”
Otherwise
print “Fail”
End if
A. Fail
B. None of the mentioned options
C. Error in the logic of the pseudocode
D. Success
QUESTION 9
What will be the output of the following pseudocode for input a = 30, b = 60, c = 90?
Integer a, b, c, sum
Read a, b, c.
Set sum = a + b + c.
if ((sum EQUALS 180) and (a NOT EQUALS 0) and (b NOT EQUALS 0) and (c NOT EQUALS 0))
print “Success”
Otherwise
print “Fail”
End if
A. Fail
B. None of the mentioned options
C. Error in the logic of the pseudocode
D. Success
D
QUESTION 10
What will be the output of the following pseudocode for a=10 b=6?
Integer func(Integer a,Integer b)
Integer temp
While(b)
temp=a Mod b
a=b
b=temp
end while
return a
}
A. 1
B. 2
C. 3
D. 4
QUESTION 10
What will be the output of the following pseudocode for a=10 b=6?
Integer func(Integer a,Integer b)
Integer temp
While(b)
temp=a Mod b
a=b
b=temp
end while
return a
}
A. 1
B. 2
C. 3
D. 4
B
Question : 1
Akhil is given a task to print Armstrong numbers within the given limit.
Input:
Read two integers n,m
Output:
Print the Armstrong numbers within the given limit.
Input :
100 400
Output:
153 370 371
lower = int(input())
upper = int(input())
for num in range(lower, upper + 1):
order = len(str(num))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num)
Question : 1
int main()
{
int start, end, i, temp1, temp2, remainder, n = 0, result = 0;
scanf(“%d %d”, &start, &end);
for(i = start + 1; i < end; ++i){
temp2 = i;
temp1 = i;
while (temp1 != 0){
temp1 /= 10;
++n;
}
while (temp2 != 0){
remainder = temp2 % 10;
result += pow(remainder, n);
temp2 /= 10;
}
if (result == i) {
printf(“%d “, i);
}
n = 0;
result = 0;
}
printf(“n”);
return 0;
}
Question : 2
Manan was amazed by his 1st geography class where he got to know how the earth revolves around the
sun and how are we getting leap year i.e 1 extra day after every 4 years Now he wants to write a program
to check whether a year is leap year or not.
Input Format:
Read a year.
Output Format:
Print whether the year is leap or not.
Test Cases:
Input:
1900
Output:
Not a leap year
Question : 3
Program to find all possible permutations in which 'n' people can occupy 'r' seats in a theater is
discussed here.
N friends are planning to go to a movie. One among them suggested few movies and all others started
to discuss and finally they selected a movie. One among them quickly booked their tickets online, to
their surprise they are unable to select their seats. All of them got confused. Then anyhow, decided to
go to the movie. They rushed to reach the theater on time. Again they are surprised that no one was
there in the theater. They are the only people about to watch the movie. There is 'r' number of seats
in which, 'n' number persons should sit. In how many ways they can sit inside the theater?
Given the number of people 'n' and the number of seats 'r' as input. The task is to find the different
number of ways in which 'n' number of people can be seated in those 'r' number of seats.
Question : 3
For example,
Input:
Number of people: 5
Number of Rows: 3
Output:
The total number of ways in which 'n' people can be seated in 'r' seats = 60.
Calculation:
P(n,r) =P(5,3)
=5! /(5?3)! = 5! / ( 5 ? 3 )!
= 120 / 2 = 60
Question:4
Write a program to implement a bubble sort algorithm for sorting the elements of an array.
Input Format:
The first line corresponds to the size of an array.
The second line corresponds to the elements.
Output Format:
Print the element in ascending order.
Sample Input:
6
11 15 26 38 9 10
Sample Output:
9 10 11 15 26 38
Question : 5
Harry is small kid and he loves to print different patterns now he himself came up with a task to
print the pattern.
Sample Input 1:
4
Sample Output 1:
4 4 4 4
4 4 1 4
4 4 2 4
4 4 3 4
4 4 4 4
Question : 5
Sample Input 2:
3
Sample Output 2:
3 3 3
3 1 3
3 2 3
3 3 3

Tech-1.pptx

  • 1.
  • 2.
    QUESTION 1 What willbe the output of the following pseudocode for x = 9, y = 7? Integer fun(Integer x, Integer y) Integer z Set z = 2 y = y mod z x = x mod z return x + y End function fun() A. 17 B. 5 C. 2 D. -5
  • 3.
    QUESTION 1 What willbe the output of the following pseudocode for x = 9, y = 7? Integer fun(Integer x, Integer y) Integer z Set z = 2 y = y mod z x = x mod z return x + y End function fun() A. 17 B. 5 C. 2 D. -5 C
  • 4.
    QUESTION 2 What willbe the output of the following pseudocode? Integer p, q, r Set p = 8, q = 6,r = 4 if(p > q) p = q Else q = p End if if(r > q) r = q Else q = r End if Print p + q + r A. 13 B. 17 C. 14 D. 23
  • 5.
    QUESTION 2 What willbe the output of the following pseudocode? Integer p, q, r Set p = 8, q = 6,r = 4 if(p > q) p = q Else q = p End if if(r > q) r = q Else q = r End if Print p + q + r C A. 13 B. 17 C. 14 D. 23
  • 6.
    QUESTION 3 What willbe the output of the following pseudocode? Integer e, f, g Set e = 1, f = 1, g = 7 e = e + f if(e + f) if(f + (g ^ e)) e = 2 f = e End if End if Print e + f + g A. 11 B. 6 C. 12 D. 22
  • 7.
    QUESTION 3 What willbe the output of the following pseudocode? Integer e, f, g Set e = 1, f = 1, g = 7 e = e + f if(e + f) if(f + (g ^ e)) e = 2 f = e End if End if Print e + f + g A. 11 B. 6 C. 12 D. 22 A
  • 8.
    QUESTION 4 What willbe the output of the following pseudocode? Integer pq, qr, rs, sp Set pq=1, qr = 1 for (each rs from 0 to 2 ) for (each sp from -4 to -2 ) pq = pq + 2 if(pq > rs) Continue End if pq = 1 if(pq > sp) Jump out of the loop End if End for End for Print pq + qr A. 13 B. 24 C. 35 D. 20
  • 9.
    QUESTION 4 What willbe the output of the following pseudocode? Integer pq, qr, rs, sp Set pq=1, qr = 1 for (each rs from 0 to 2 ) for (each sp from -4 to -2 ) pq = pq + 2 if(pq > rs) Continue End if pq = 1 if(pq > sp) Jump out of the loop End if End for End for Print pq + qr D A. 13 B. 24 C. 35 D. 20
  • 10.
    QUESTION 5 What willbe the output of the following pseudocode? Integer x, y, z Set y = 30, x = 10, z = 20 if (y > (z + x)) y = 1 else x = x - 2 z = z - 2 End if if (z > (y + x) || 1) y = (0 ^ 5) else x = x + 2 z = x + 2 End if Print x + y + z A. 20 B. 24 C. 30 D. 31
  • 11.
    QUESTION 5 What willbe the output of the following pseudocode? Integer x, y, z Set y = 30, x = 10, z = 20 if (y > (z + x)) y = 1 else x = x - 2 z = z - 2 End if if (z > (y + x) || 1) y = (0 ^ 5) else x = x + 2 z = x + 2 End if Print x + y + z D A. 20 B. 24 C. 30 D. 31
  • 12.
    QUESTION 6 What willbe the output of the following pseudocode? Integer var_ a = 50, var_ b = 23, var_ c var_ c = var_ a + var_ b var_ c = var_ c MOD var_ b var_ b = var_ b + var_ c var_ a = var_ a - var_ b Print var_ a, var_ b, var_ c A. 23 27 4 B. 23 17 3 C. 77 27 4 D. 69 19 4
  • 13.
    QUESTION 6 What willbe the output of the following pseudocode? Integer var_ a = 50, var_ b = 23, var_ c var_ c = var_ a + var_ b var_ c = var_ c MOD var_ b var_ b = var_ b + var_ c var_ a = var_ a - var_ b Print var_ a, var_ b, var_ c A. 23 27 4 B. 23 17 3 C. 77 27 4 D. 69 19 4 A
  • 14.
    QUESTION 7 What willbe the output of the following pseudo code: Integer _m Set _m = 0 Integer _p[5] = {1, 1, 0, 1, 7} if (_p[0] && _p[4]) _m = _p[1] End if if (_p[2] && _p[3]) _m = _p[2] End if Print _m A. 18 B. 1 C. -5 D. 4
  • 15.
    QUESTION 7 What willbe the output of the following pseudo code: Integer _m Set _m = 0 Integer _p[5] = {1, 1, 0, 1, 7} if (_p[0] && _p[4]) _m = _p[1] End if if (_p[2] && _p[3]) _m = _p[2] End if Print _m A. 18 B. 1 C. -5 D. 4 B
  • 16.
    QUESTION 8 What willbe the output of the following pseudocode Integer x, y, z, a Set x=2, y=1, z=5 a=(x AND y) OR (z+1) Print a A. 2 B. 3 C. 5 D. 6
  • 17.
    QUESTION 8 What willbe the output of the following pseudocode Integer x, y, z, a Set x=2, y=1, z=5 a=(x AND y) OR (z+1) Print a A. 2 B. 3 C. 5 D. 6 D
  • 18.
    QUESTION 9 What willbe the output of the following pseudocode for input a = 30, b = 60, c = 90? Integer a, b, c, sum Read a, b, c. Set sum = a + b + c. if ((sum EQUALS 180) and (a NOT EQUALS 0) and (b NOT EQUALS 0) and (c NOT EQUALS 0)) print “Success” Otherwise print “Fail” End if A. Fail B. None of the mentioned options C. Error in the logic of the pseudocode D. Success
  • 19.
    QUESTION 9 What willbe the output of the following pseudocode for input a = 30, b = 60, c = 90? Integer a, b, c, sum Read a, b, c. Set sum = a + b + c. if ((sum EQUALS 180) and (a NOT EQUALS 0) and (b NOT EQUALS 0) and (c NOT EQUALS 0)) print “Success” Otherwise print “Fail” End if A. Fail B. None of the mentioned options C. Error in the logic of the pseudocode D. Success D
  • 20.
    QUESTION 10 What willbe the output of the following pseudocode for a=10 b=6? Integer func(Integer a,Integer b) Integer temp While(b) temp=a Mod b a=b b=temp end while return a } A. 1 B. 2 C. 3 D. 4
  • 21.
    QUESTION 10 What willbe the output of the following pseudocode for a=10 b=6? Integer func(Integer a,Integer b) Integer temp While(b) temp=a Mod b a=b b=temp end while return a } A. 1 B. 2 C. 3 D. 4 B
  • 22.
    Question : 1 Akhilis given a task to print Armstrong numbers within the given limit. Input: Read two integers n,m Output: Print the Armstrong numbers within the given limit. Input : 100 400 Output: 153 370 371
  • 23.
    lower = int(input()) upper= int(input()) for num in range(lower, upper + 1): order = len(str(num)) sum = 0 temp = num while temp > 0: digit = temp % 10 sum += digit ** order temp //= 10 if num == sum: print(num)
  • 24.
    Question : 1 intmain() { int start, end, i, temp1, temp2, remainder, n = 0, result = 0; scanf(“%d %d”, &start, &end); for(i = start + 1; i < end; ++i){ temp2 = i; temp1 = i; while (temp1 != 0){ temp1 /= 10; ++n; } while (temp2 != 0){ remainder = temp2 % 10; result += pow(remainder, n); temp2 /= 10; } if (result == i) { printf(“%d “, i); } n = 0; result = 0; } printf(“n”); return 0; }
  • 25.
    Question : 2 Mananwas amazed by his 1st geography class where he got to know how the earth revolves around the sun and how are we getting leap year i.e 1 extra day after every 4 years Now he wants to write a program to check whether a year is leap year or not. Input Format: Read a year. Output Format: Print whether the year is leap or not. Test Cases: Input: 1900 Output: Not a leap year
  • 26.
    Question : 3 Programto find all possible permutations in which 'n' people can occupy 'r' seats in a theater is discussed here. N friends are planning to go to a movie. One among them suggested few movies and all others started to discuss and finally they selected a movie. One among them quickly booked their tickets online, to their surprise they are unable to select their seats. All of them got confused. Then anyhow, decided to go to the movie. They rushed to reach the theater on time. Again they are surprised that no one was there in the theater. They are the only people about to watch the movie. There is 'r' number of seats in which, 'n' number persons should sit. In how many ways they can sit inside the theater? Given the number of people 'n' and the number of seats 'r' as input. The task is to find the different number of ways in which 'n' number of people can be seated in those 'r' number of seats.
  • 27.
    Question : 3 Forexample, Input: Number of people: 5 Number of Rows: 3 Output: The total number of ways in which 'n' people can be seated in 'r' seats = 60. Calculation: P(n,r) =P(5,3) =5! /(5?3)! = 5! / ( 5 ? 3 )! = 120 / 2 = 60
  • 28.
    Question:4 Write a programto implement a bubble sort algorithm for sorting the elements of an array. Input Format: The first line corresponds to the size of an array. The second line corresponds to the elements. Output Format: Print the element in ascending order. Sample Input: 6 11 15 26 38 9 10 Sample Output: 9 10 11 15 26 38
  • 29.
    Question : 5 Harryis small kid and he loves to print different patterns now he himself came up with a task to print the pattern. Sample Input 1: 4 Sample Output 1: 4 4 4 4 4 4 1 4 4 4 2 4 4 4 3 4 4 4 4 4
  • 30.
    Question : 5 SampleInput 2: 3 Sample Output 2: 3 3 3 3 1 3 3 2 3 3 3 3

Editor's Notes

  • #3 [Note- mod finds the remainder after the division of one number by another. For example, the expression "5 mod 2 leaves a quotient of 2 and a remainder of 1.]
  • #4 [Note- mod finds the remainder after the division of one number by another. For example, the expression "5 mod 2 leaves a quotient of 2 and a remainder of 1.]
  • #7  [Note- ^ is the bitwise exclusive OR operator that compares each bit of its first operand to the corresponding bit of other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0. If(x) gets executed if the value inside ifo, i.e., x is not zero]
  • #8  [Note- ^ is the bitwise exclusive OR operator that compares each bit of its first operand to the corresponding bit of other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0. If(x) gets executed if the value inside ifo, i.e., x is not zero]
  • #9 [Note- Continue: When a continue statement is encountered inside a loo of statements inside the body of the loop for the current iteration.
  • #10 [Note- Continue: When a continue statement is encountered inside a loo of statements inside the body of the loop for the current iteration.
  • #11  [Note- ^ is the bitwise exclusive OR operator that compares each bit of its first operand to the corresponding bit of its second op other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0] 0^5=0
  • #12  [Note- ^ is the bitwise exclusive OR operator that compares each bit of its first operand to the corresponding bit of its second op other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0] 0^5=0
  • #13  [Note: MOD finds the remainder after the division of one number by another. For example, the 2 leaves a quotient of 2 and a remainder of 1)
  • #14  [Note: MOD finds the remainder after the division of one number by another. For example, the 2 leaves a quotient of 2 and a remainder of 1)
  • #15  [Note-&&: Logical AND - The logical AND operator (88) returns the Boolean value true(or 1) if both operands are true and 1f(x) gets executed if the value inside it, Le., x is not zero]
  • #16  [Note-&&: Logical AND - The logical AND operator (88) returns the Boolean value true(or 1) if both operands are true and 1f(x) gets executed if the value inside it, Le., x is not zero]
  • #17 D
  • #18 D
  • #19 D
  • #20 D
  • #23 lower = int(input()) upper = int(input()) for num in range(lower, upper + 1): order = len(str(num)) sum = 0 temp = num while temp > 0: digit = temp % 10 sum += digit ** order temp //= 10 if num == sum: print(num)
  • #26 y = int(input()) if (y % 400 == 0) or (y % 100 != 0 and y %4 == 0): print(y,"is leap year.") else: print(y,"isn't leap year.") 0
  • #27 def fact(n): fact=1 for i in range(1,n+1): fact=fact*I return fact n=int(input()) r= int(input()) a= fact(n) b=fact(n-r) c=b//a print(c)
  • #29 def bubbleSort(array): for i in range(len(array)): for j in range(0, len(array) - i - 1): if array[j] > array[j + 1]: temp = array[j] array[j] = array[j+1] array[j+1] = temp n=int(input()) ele=int(input().split()) bubbleSort(ele) print(ele) #include <stdio.h> void bubbleSort(int arr[], int n) { int i, j, temp; for(i = 0; i < n; i++) { for(j = 0; j < n-i-1; j++) { if( arr[j] > arr[j+1]) { temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } } int main() { int arr[100], i, n, step, temp; scanf("%d", &n); for(i = 0; i < n; i++) { scanf("%d", &arr[i]); } bubbleSort(arr, n); for(i = 0; i < n; i++) { printf("%d ", arr[i]); } return 0; }
  • #30 n=int(input()) count=0 for i in range(1,n+2): for j in range(1,n+1): if (i!=1 AND j==n-1): print(c) count=count+1 else: print(n)