0% found this document useful (0 votes)
33 views15 pages

Algorithms Section 1,2

The document provides examples of algorithms and flowcharts to solve various mathematical and logical problems. It includes 10 questions that each describe a problem and ask the reader to write an algorithm and draw a flowchart to solve it. The questions cover topics like calculating sums, averages, largest/smallest values, printing sequences, and factorials. Pseudocode and flowcharts are provided as solutions for each question.

Uploaded by

mo3azsaif.74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views15 pages

Algorithms Section 1,2

The document provides examples of algorithms and flowcharts to solve various mathematical and logical problems. It includes 10 questions that each describe a problem and ask the reader to write an algorithm and draw a flowchart to solve it. The questions cover topics like calculating sums, averages, largest/smallest values, printing sequences, and factorials. Pseudocode and flowcharts are provided as solutions for each question.

Uploaded by

mo3azsaif.74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Algorithms

Section ( 1 , 2 )
Flowcharts Pseudo-Codes
 A visual way of representing by diagrams  A description of the algorithm steps
that uses shapes, lines, and arrows to using a mixture of programming
sequence steps. languages and English statements.

MO3AZ
Pseudo-Codes
 A description of the algorithm steps using a mixture of programming languages and
English statements.

MO3AZ
Pseudo-Codes
Start Input IF Statement
START READ n IF ConditionTHEN
Statements
End Output ELSE
END PRINT n Statements
END IF

Variable and
SET nProcess
=1 Loop
SET Sum = Sum + n GO TO step 4

MO3AZ
Q1 : Write an algorithm and draw a flowchart to sum two numbers

Start

1) START Read n1, n2

2) READ n1,n2
Sum = n1 + n2
3) SET Sum = n1+n2
4) PRINT Sum Print Sum
5) END
End

MO3AZ
Q2 : Write an algorithm and draw flowchart to calculate area of
rectangle the length L , and the width of the rectangle W

Start

1) START Read L , W

2) READ L , W
Area = L * W
3) SET Area = L * W
4) PRINT Area Print Area
5) END
End

MO3AZ
Q3 : Write an algorithm and draw a flowchart to find the average of 3
integers Algorithm.

Start

1) START Read n1, n2 , n3

2) READ n1,n2,n3
Avg = (n1 + n2 + n3 ) / 3
3) SET Avg =
(n1+n2+n3)/3 Print Avg

4) PRINT Avg
End
5) END
MO3AZ
Q4 : Write an algorithm and draw a flowchart to find the largest of
two numbers Algorithm

Start
1) START
2) READ a , b Read a , b
3) IF a > b THEN
4) PRINT a YES NO
a>b?
5) ELSE
6) PRINT b
Print a Print b
7) END IF
8) END End

MO3AZ
Q5 : Write an algorithm and draw a flowchart to find the largest of
three numbers
1) START
Start
2) READ a , b , c
3) IF a > b THEN
4) IF a > c THEN Read a, b , c
5) PRINT a
6) ELSE
7) PRINT c YES NO
8) END IF a>b?
9) ELSE NO NO
a>c? b>c?
10) IF b > c THEN
11) PRINT b YES YES
12) ELSE Print c
13) PRINT c Print a Print b
14) END IF
15) END IF End
16) END MO3AZ
Q5 : Write an algorithm and draw a flowchart to find the largest of
three numbers [ ANOTHER SOLUTION ]

Start
1) START
2) READ a , b , c
Read a, b , c
3) IF a >= b AND a >= c
THEN
4) PRINT a YES NO
a >= b &&
5) ELSE
a >= c ?
6) IF b >= a AND b >= c
b >= a &&
THEN NO b >= c ?
7) PRINT b
8) ELSE Print c YES
1) PRINT c
9) END IF Print a Print b
10) END IF
11) END End MO3AZ
Q6 : Write an algorithm and draw flow chart to print natural
numbers from 1 to 100.

Start

1) START
2) SET i = 1 i=1

3) IF i <= 100 THEN


YES NO
4) PRINT i i <= 100 ?
5) SET i = i + 1
Print i
6) GO TO step 3
7) END IF
i=i+1
8) END
End

MO3AZ
Q7 : Write an algorithm and draw a flow chart to calculate sum of
numbers 0 ---> 100

Start

1) START
2) SET i = 0 , Sum = 0 i = 0 , Sum = 0

3) IF i <= 100 THEN


YES NO
4) SET Sum = Sum + i i <= 100 ?
5) SET i = i + 1
6) GO TO step 3 Sum = Sum + i Print Sum

7) END IF
i=i+1
8) PRINT Sum End
9) END
MO3AZ
Q8 : Write an algorithm and draw a flow chart to print even
numbers from 16 to 48.

Start

1) START
i = 16
2) SET i = 16
3) IF i <= 48 THEN
YES NO
4) PRINT i i <= 48 ?

5) SET i = i + 2
Print i
6) GO TO step 3
7) END IF i=i+2
8) END End

MO3AZ
Q9 : Write an algorithm and draw a flowchart to calculate sum of
the age of student and print sum and average
1) START Start
2) READ n
Read n
3) SET i = 1 , Sum = 0
4) IF i <= n THEN i = 1 , Sum = 0
5) READ Age
6) SET Sum = Sum + YES NO
Age i <= n ?
7) SET i = i + 1 Read Age
Avg = Sum / n
8) GO TO step 4
Sum = Sum + Age
9) END IF Print Sum , Avg
10) SET Avg = Sum / n i=i+1
End
11) PRINT Sum , Avg
MO3AZ
Q10 : Write an algorithm and draw a flow chart to find factorial of n
Algorithm
Start
1) START
Read n
2) READ n
3) SET i = 1 , Fact = 1 i = 1 , Fact = 1
4) IF i <= n THEN
5) SET Fact = Fact * i YES NO
i <= n ?
6) SET i = i + 1
7) GO TO step 4 Fact = Fact * i
Print Fact
8) END IF
9) PRINT Fact i=i+1
10) END End
MO3AZ

You might also like