11th CS Program Analysis-2
11th CS Program Analysis-2
Program Analysis:
What is program:
Step 1: Start
Step 2: Declare variables num1, num2 sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum = num1+num2
Step 5: Display sum
Step 6: Stop
Write an algorithm to find the square of a number.
Start
Step 1 : Start
Step 2 : Input a number As Num,
C Read
Number
Step 3 : Multiply the number A ‘Num’
twice by itself
Num*Num C=Num * Num
Step 3 : Store result In C
◦ C=Num* Num Display
Step 4 : Display C C
5.Connectors:
Whenever flowchart becomes complex or it spreads over more than one page, it is useful to use
connectors to avoid any confusions. It is represented by a circle.
circular flow chart shape used to indicate a jump in the process flow
7. Flow lines: Flow lines indicate the exact sequence in which instructions are executed.
Arrows represent the direction of flow of control and relationship among different symbols of flowchart.
Advantages of Flowchart:
• Flowcharts are better way of communicating the logic of system.
• Flowcharts act as a guide for blueprint during program designed.
• Flowcharts helps in debugging process.
• With the help of flowcharts programs can be easily analysed.
• It provides better documentation.
• Flowcharts serve as a good proper documentation.
Disadvantages of Flowchart:
• It is difficult to draw flowchart for large and complex programs.
• In this their is no standard to determine the amount of detail.
• Difficult to reproduce the flowcharts.
• It is very difficult to modify the Flowchart.
Example : Draw a flowchart to input two numbers from user and display the largest of two numbers
Example : Draw a flowchart to input two numbers from user and display the largest of two
numbers
Example : Draw a flowchart for accept in 3subjects and find sum and average
Pseudocode
Definition:
◦ It is a programming analysis used for planning program logic.
◦ Pseudocode is tool used to solve problems of computer programs.
◦ Pseudocode is a detailed description of an algorithm which explains the function to be performed by the program.
◦ Pseudocode is one of the initial processes in the program development.
◦ Pseudocode is expressed in natural language, written in formal style which can be easily read and understood by
anyone.
◦ It can be said a template which is used for writing detailed instructions/ coding in a specific programming
language.
◦ Advantages:
◦ 1. Converting a pseudocode to programming language is much more easier as compared to flowchart.
◦ 2. It is used to write pseudocode as compared to drawing flowchart and actual program.
3.Pseudocode uses English like statements. Therefore, it can be written easily and quickly.
4.In pseudocode, each step is independent of other steps. Therefore, if any modification is done in any step, it does
not affect the codes of other module i.e. the code has not to be rewritten if any change occurs in any other step.
◦ Limitations:
1.Pseudocode is textual representation of an algorithm.
2. It does not provide graphical representation. Therefore, sometimes, it
becomes difficult to understand the complex logic written in
pseudocode.
3..When too many nested conditions are used in the pseudocode, the
level of difficulty to understand the code increases.
3.Graphic representations of program logic is not available in pseudo
codo.
Start
Declare A, B
Read A,B
If NO
A>B
YES
Display A Display B
Stop
Swapping of 2 numbers
Here in this algorithm we declare 3 variables to store integers ,then we input two numbers lets say 10 and 20. In the computer it gets
stored as a=10 and b=20 and we declare a variable T because if we put a=b then the value of b gets stores in a and then valuegets
removed ,so we put the value of a in t i.e. t=a, so t becomes 10 then we put a=b so a becomes 20. Now we put value of t that stored the
value of a in b ,b=a b becomes 10.
Step 1: Start
Step 2:Declare variables A, B and T as integer
Step 3: Read value of A and B
Step 4: T=A
Step 5: A=B
Step 6. B=T
Step 7. Print A
Step 8. Print B
Step 9. Stop A=10 B=20
OUTPUT: B=20 A=10
Step 1: Start
Step 2: Declare Variable n, fact, i
Step 3: Read number n
Read marks in
subjects as sub1,
sub2,sub3
Average = sum/3
STOP
Start
Read N
If
N%2==0
YES
STOP
Start
Declare A, B
Read A,B
If NO
A>B
YES
Display A Display B
Stop