Problem 1
Problem 1
4182
PROBLEM 1
Pseudo code:
Variables:
INPUT Variables: Value 1 (Value on the first throw of dice), Value 2 (Value on the second throw
of dice), Value 3 (Value on the third throw of dice). (Integer Numbers).
Page 1
(ITC-A) Assignment 2 Roll No: 10L-
4182
Flow Chart:
Start
Input Value1,
Value2,
Value3.
If Value1 = 5
OR Value1 = 6
No
Yes
If Value2 = 3
No
OR Value2 = 4
Yes
Yes
Output You
won
Stop
Page 2
(ITC-A) Assignment 2 Roll No: 10L-
4182
PROBLEM 2
Pseudo code:
Variables:
INPUT Variables: n (number of elements in the set), a0….an-1 (variables for holding individual
elements in the set from first to last), c (variable used for comparing two values), f (variable
used for holding the minimum value in the set. (Integer Numbers).
1. Take n
2. flag = 0
3. While flag = 0
a. x = 1
b. While x <= n
i. Take value in ax
ii. x = x + 1
c. End while
d. c = 1, m = 1, o = 2
e. While c < n
i. If am < ao
1. o = o + 1
ii. Else
1. m = m + 2
iii. End if
iv. c = c + 1
f. End while
g. If am <= ao
i. am = f
h. Else
i. ao = f
i. End if
j. g = 1, count = 0
k. While ag <= an
i. If ag = f
1. count = count + 1
2. x = x + 1
ii. Else
1. x = x + 1
iii. End if
Page 3
(ITC-A) Assignment 2 Roll No: 10L-
4182
iv. If count = 1
1. Display “f” is repeated 1 time
v. Else
1. Display “f” is repeated “count” times
vi. End if
l. End while
m. i = 1
n. While i <= n
i. If ai = f
1. ai = NULL
2. i = i + 1
ii. Else
1. i = i + 1
iii. End if
o. End while
p. n = n – count
q. If n = 0
i. Flag = 1
r. End if
4. End while
5. End
PROBLEM 3
Pseudo code:
Variables:
INPUT Variables: e (number of elements in the set), a0….ae-1 (variables for holding individual
elements of the set from first to last), z (variable for counting no of minimum values recorded
thus far), x (variable for comparing two values of the set): (Integer Numbers).
OUTPUT Variables: Minimum value, 2nd minimum value, 3rd minimum value, 4th minimum value
and the 5th minimum value. (Integer Numbers).
1. Take e
2. While e >= 5
a. q= 0
b. While q < e
i. Input Number at aq
ii. q = q + 1
c. End while
Page 4
(ITC-A) Assignment 2 Roll No: 10L-
4182
d. i = 0, d = 1, x = 1
e. While z < = 5
i. While x < e
1. If ai <= ad
a. d = d + 1
b. x = x + 1
2. Else
a. i = i + 1
b. x = x + 1
3. End if
ii. End while
iii. If ai < ad
1. ai = f
2. Display f
3. z = z + 1
iv. Else
1. ad = f
2. Display f
3. z = z + 1
v. End if
vi. count = 0
vii. g = 0
viii. While g < e
1. If ag = f
a. ag = NULL
b. count = count + 1
c. g = g + 1
2. Else
a. g = g + 1
3. End if
ix. End while
x. e = e – count
f. End while
3. End while
4. End
Page 5
(ITC-A) Assignment 2 Roll No: 10L-
4182
PROBLEM 4
Pseudo code:
Variables:
INPUT Variables: m and n (two values whose GCD is required), s and g ( used in place of
remainder) , s (also used as divisor)(Integer Numbers).
1. Take m, n
2. If m < n
a. While s >= 0 + m
i. s = n – m
b. End while
3. Else
a. While s >= 0 + n
i. s = m - n
b. End while
4. End if
5. If s = 0
a. Display n is GCD of m and n
6. End if
7. While g > 0
a. While g >= 0 + s
i. g = m – s
b. End while
c. If g = 0
i. Display g is GCD of m and n
d. Else
i. m = s
ii. s = g
iii. g = 1 + s
e. End if
8. End while
9. End
Page 6
(ITC-A) Assignment 2 Roll No: 10L-
4182
PROBLEM 5
Pseudo code:
Variables:
INPUT Variables: s (no of elements in set 1), n (no of elements in set 2) , sum1 (for storing sum
of all elements in set 1), sum2 (for storing sum of all elements in set 2)(Integer Numbers).
OUTPUT Variables: sum2 is greater than sum1 OR sum1 is greater than sum2 OR sum1 and
sum2 are equal (Message).
1. Take s, n
2. i = 0, c = 0, sum1 = 0, sum2 = 0
3. While i < s
a. Input value in ai
b. i=i+1
4. End while
5. While c < n
a. Input value in bc
b. c=c+1
6. End while
7. i = 0, c = 0
8. While i < s
a. sum1 = sum1 + ai
b. i=i+1
9. End while
10. While c < n
a. sum2 = sum2 + bc
b. c=c+1
11. End while
12. If sum1 < sum2
a. Display sum2 is greater than sum1
13. Else
a. If sum1 > sum2
i. Display sum1 is greater than sum2
b. Else
i. Display sum1 and sum2 are same
c. End if
14. End if
15. End
Page 7
(ITC-A) Assignment 2 Roll No: 10L-
4182
PROBLEM 6
Pseudo code:
Variables:
1. i = 0 , k = 0, a = 0
2. While k < N
a. While i < N
i. c = xi[(3.14/N)*i*(k + ½)^i + 5]
ii. a = a + c
iii. i = i + 1
b. End while
c. xk = (1/2)xo + a
d. xi = xk
e. Display xi is the transformed k + 1 element of the set
f. k = k + 1
g. i = i + 1
h. a = 0
3. End while
4. End
Page 8