Professional Documents
Culture Documents
Assignment No 3 Solutions
Assignment No 3 Solutions
Section: b
Assignment No 3 Solutions:
Q1:
Features:
Algorithm:
Requirements:
Three numbers, +ve or ve
Scope:
Find Greater of three given numbers
Inputs:
1) Three numbers
Steps:
1) Take three numbers (+ve or ve ) from user.
2) Compare every number individually with every other number using
conditional operator.
3) If 1st number is a , 2nd is b and 3rd is c then if a >b ,a>c then a is greater of all.
4) If b>a , b>c then b is Greater.
5) If c>a , c>b then c is greater of all.
6) And if a=b=c then all are equal.
7) And if a=b , a is not equal to c then a and b are equal accordingly.
8) And if b=c and b is not equals a then b and c are equal.
9) And if c=a and c is not equals b then c is equals a.
10)
Implement these conditions using conditional statements or loops.
Output:
e.g.
REF # L1F12BSCS2063
Section: b
a = 45, b= 2, c= 3
a>b, a>c
45.2
, 45>3
1and1=1 (true)
-----------------------b>a, b>c
2>45, 2>3
0and0=0(false)
-------------------------c>a, c>b
3>45, 3>2
0and1=0(false)
So the number entered 45 is Greater of all
Q2:
Algorithm:
Requirements:
Number +ve or ve .
Scope:
Find the factorial of given number.
Input:
1) Get a number n from the user.
Steps:
1) Take the number n from the user.
2) Multiply number n with its smaller number which is a (where a=n-1). So
m=n*a
REF # L1F12BSCS2063
Section: b
Q3:
Algorithm:
Requirements:
Natural number 1 -20
Even numbers are multiple of 2.
+ve numbers
Scope:
Find sum of even numbers b/w 1-20
Inputs:
Take 1 20 numbers
Steps:
1) Take variable a equals 2
2) Take variable b equals 0
3) Now make a loop of which (count = count + a) and at the end of loop put a =
a+2.
4) Condition of the loop will be if a>22 iteration should stops.
5) Now count variable will work as adder of even numbers, and a will be used
as an iteration handler.
6) When a>22 the iteration stops and display Sum of 1-20 even numbers are
count.
REF # L1F12BSCS2063
Section: b
Output:
Condition: a >22 iteration stops.
a = 2, count =count + a = 0+2= 2, a = a+2 = 2+2 = 4
a = 4, count = count +a = 2+2 =4, a = a+2 = 4+2 =6
.
.
a =18, count = count +a = 72 + 18 = 90, a =a+2 =18+2 =20
a = 20, count =count +a = 90 + 20 = 120, a = a+2 = 20+2 =22
a =22, (condition satisfied) iteration stops.
Ref# L1F12BSCS2063
Name: Zulqurnain jutt