Professional Documents
Culture Documents
PPS Unit-1
PPS Unit-1
Solving
B. Tech – 2nd Semester
Unit I: Introduction
2. E. Balaguruswamy,
Programming in ANSI C, Tata
McGraw-Hill
Reference Books:
Brian W. Kernighan and
Dennis M. Ritchie, The C
Programming Language,
Prentice Hall of India
Other Book
Let’s Us C by Yashwant Kanetkar,
INTRODUCTION TO COMPUTERS
2. Storing: The data & instructions are stored for either initial
or additional processing, as & when required.
or
Step 1: Start
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 1: Start
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 6: Stop.
Algorithm
Control Structures are just a way to specify flow of
control in programs.
computer.
Algorithm
Selection Logic (Conditional Flow)Selection Logic simply
involves a number of conditions or parameters which
decides one out of several written modules. The
structures which use these type of logic are known
as Conditional Structures.
Step 1: Start
Step 2: Declare variable a, b, c, n, i
Step 3: Initialize variable a=0, b=1, i=2
Step 4: Read n from user
Step 5: Print a and b
Step 6: Repeat until i < n (<- less than)
6.1 c = a + b
6.2 print c
6.3 a=b, b=c
6.4 i=i+1
Step 7: Stop
Algorithm to find all the roots of the quadratic equation
Step 1: Start
Step 2: Declare variables a, b, c, D, x1, x2, rp and ip;
Step 3: Calculate discriminant D ← b2-4ac
Step 4: If D ≥ 0
r1 ← (-b+√D)/2a and r2 ← (-b-√D)/2a
Display r1 and r2 as roots.
Else Calculate real part and imaginary part
rp ← - b/2a
ip ← √(-D)/2a
Display rp+j(ip) and rp-j(ip) as roots
Step 5: Stop
Algorithm to find the factorial
Step 1: Start
Step 2: Declare variables n, factorial and i.
Step 3: Initialize variables
factorial ← 1
i←1
Step 4: Read value of n
Step 5: Repeat the steps until i <= n
5.1: factorial ← factorial * i
5.2: i ← i+1
Step 6: Display factorial
Step 7: Stop
Algorithm to check prime number
Step 1: Start
flag ← 1
i←2
Advantages of Algorithms:
It is easy to understand.
Disadvantages of Algorithms:
Average =
(num1+num2)/2
Print Average
Stop
Control structures in flowchart
Enter n
Set
Factorial=1
Yes
Is Print
n=1 Factorial
No
Factorial=Factorial*n
Stop
n=n-1
Advantages Of Using FLOWCHARTS
Communication: - Flowcharts are better way of
communicating the logic of a system to all concerned.
Effective analysis: - With the help of flowchart, problem
can be analyzed in more effective way.
Proper documentation: - Program flowcharts serve as a
good program documentation, which is needed for
various purposes.
Efficient Program Maintenance: - The maintenance of
operating program becomes easy with the help of
flowchart. It helps the programmer to put efforts more
efficiently on that part
Pseudocode
Pseudocode
Step1:Start
Step2:Print "Enter Any Number to Check, Even or Odd"
Step3:Read input of a number
Step4:If number mod 2 = 0
Print "Number is Even“
else
Print "Number is Odd“
Step5:End
Pseudocode
Pseudocode for Factorial of a number :
Step 1: Start.
Step 2: Declare N and F as integer variable.
Step 3: Initialize F=1.
Step 4: Enter the value of N.
Step 5: Check whether N>0, if not then F=1.
Step 6: If yes then, F=F*N
Step 7: Decrease the value of N by 1 .
Step 8: Repeat step 6 and 7 until N=0.
Step 9: Now print the value of F.
Step 10: Stop.
Advantages of Pseudocode
“or”