Pseudocode is a compact and informal high-level description of a program using the conventions of a programming language, but intended more for humans.
Pseudocode is not an actual programming language. So it cannot be compiled into an executable program. It uses short terms or simple English language syntaxes to write code for programs before it is actually converted into a specific programming language.
And there is no pseudocode standard syntax and so at times it becomes slightly confusing when writing Pseudocode and so let us understand pseudo code with an example.
Pseudocode Example 1: Add Two Numbers.(Simple Pseudocode Example)
- BEGIN
- NUMBER s1, s2, sum
- OUTPUT("Input number1:")
- INPUT s1
- OUTPUT("Input number2:")
- INPUT s2
- sum=s1+s2
- OUTPUT sum
- END
Pseudocode Example 2: Calculate Area and Perimeter of Rectangle (Simple Pseudocode Example)
- BEGIN
- NUMBER b1,b2,area,perimeter
- INPUT b1
- INPUT b2
- area=b1*b2
- perimeter=2*(b1+b2)
- OUTPUT alan
- OUTPUT perimeter
- END
Pseudocode Example 3: Calculate sales taxes (Simple Pseudocode Example)
- BEGIN
- NUMBER price, tax, taxRate, total
- OUTPUT "Enter Product Price"
- INPUT price
- OUTPUT "Enter tax rate amoung 1 and 100"
- OKU taxRate
- tax= price* taxRate/100
- total= price + tax
- OUTPUT "Product tax="+tax
- OUTPUT "Product total price ="+total
- END
Pseudocode Example 4: Solve Quadratic Equation (Pseudocode If Else Example)
- BEGIN
- NUMBER a, b, c, d, x1, x2
- INPUT a,b,c
- d = b^2-4ac
- IF (d >= 0) THEN
- x1 = (-b+√d)/2a yada x1 = (-b+d^(1/2)/2a
- x2 = (-b-√d)/2a yada x2 = (-b-d^(1/2)/2a
- OUTPUT "ROOT 1:"+x1
- OUTPUT "ROOT 2:"+x2
- ELSE IF (d == 0) THEN
- x1=x2= -b/2a
- OUTPUT "ROOT 1:"+x1
- OUTPUT "ROOT 2:"+x2
- ELSE
- OUTPUT "There is no real root"
- ENDIF