Pseudocode Examples

Pseudocode Examples32 min read

What is Pseudocode

As you know, pseudocode is the way of expressing a program or code so that it could be easily understood by programmers of every programming languages out there.

Pseudocode is an informal high-level description of the operating principle of a computer program or an algorithm




Pseudocode is a way of describing a computer program or algorithm in plain, easy-to-understand language. It is not a formal programming language, but rather a tool that programmers use to plan and organize their code.

The purpose of pseudocode is to express the logical steps of an algorithm in a way that is easy for humans to understand, while still being independent of any specific programming language. As such, pseudocode often uses a combination of natural language and programming constructs, such as loop and conditional statements, to convey the overall structure and intent of a program.

Pseudocode is often used as an intermediate step between a problem or task description, and the writing of actual code. It can be used to plan the overall structure of a program, or to work out the details of a particular algorithm or data structure.

The structure of pseudocode can be quite flexible, but it typically follows the basic format of a programming language, with variables, assignments, control flow, and subroutines. The key difference is that pseudocode doesn’t have to adhere to strict syntax rules and it can be written in natural language.

For example, the following is a simple pseudocode algorithm that finds the largest value in an array of numbers:

It’s important to note that pseudocode is not a programming language and should not be executed by a computer. Instead, it’s meant to be a helpful tool for humans to plan and understand their programs. It is also worth mentioning that there are different conventions for writing pseudocode, as it is not standardized language, so it can be written in variety of styles.

In summary, pseudocode is a useful technique for expressing algorithms and program structures in a way that is easy for humans to understand. It is often used as a tool to help programmers plan and organize their code before they begin writing it in a specific programming language.

Following are the basic rules before writing pseudocode :

  • Write only one statement per line.
  • Write what you mean, not how to program it
  • Give proper indentation to show hierarchy and make code understandable.
  • Make the program as simple as possible.
  • Conditions and loops must be specified well ie. begun and ended explicity as in given pseudocode examples :

Example 1: WRITE A PSEUDOCODE TO FIND THE LARGEST OF TWO NUMBERS.

The above block of text is a pseudocode that compares two numbers and prints out which one is larger. Here is an explanation of each line:

  1. BEGIN is a marker that indicates the start of the program.
  2. NUMERIC nNum1,nNum2 declares two variables, nNum1 and nNum2, as numeric data types.
  3. DISPLAY "ENTER THE FIRST NUMBER : " prints the string “ENTER THE FIRST NUMBER :” to the screen.
  4. INPUT nNum1 waits for the user to enter a value, which is then stored in the variable nNum1.
  5. DISPLAY "ENTER THE SECOND NUMBER : " prints the string “ENTER THE SECOND NUMBER :” to the screen.
  6. INPUT nNum2 waits for the user to enter a value, which is then stored in the variable nNum2.
  7. IF nNum1 > nNum2 checks if the value stored in nNum1 is greater than the value stored in nNum2.
  8. If nNum1 > nNum2 is true, then the next line is executed, DISPLAY nNum1 + " is larger than "+ nNum2 which will print the value of nNum1 and a string that says ” is larger than ” and value of nNum2.
  9. If the value of nNum1 is not greater than nNum2, the next line is executed: DISPLAY nNum2 + " is larger than " + nNum1 which will print the value of nNum2 and a string that says ” is larger than ” and value of nNum1.
  10. END is a marker that indicates the end of the program.

This pseudocode will take two numbers as input from the user, compare them and prints which number is greater. It follows the basic flow of control statements, variable declarations, and user input/output.

Example 2: WRITE A PSEUDOCODE TO FIND THE SUM OF TWO NUMBERS.

The above block of text is a pseudocode that prompts the user to enter two numbers and then calculates and displays their sum. Here is an explanation of each line:

  1. BEGIN is a marker that indicates the start of the program.
  2. NUMERIC nNum1,nNum2,nSum declares three variables, nNum1, nNum2 and nSum, as numeric data types.
  3. DISPLAY "ENTER THE FIRST NUMBER : " prints the string “ENTER THE FIRST NUMBER :” to the screen.
  4. ACCEPT nNum1 waits for the user to enter a value, which is then stored in the variable nNum1.
  5. DISPLAY "ENTER THE SECOND NUMBER : " prints the string “ENTER THE SECOND NUMBER :” to the screen.
  6. ACCEPT nNum2 waits for the user to enter a value, which is then stored in the variable nNum2.
  7. COMPUTE nSum=nNum1+nNum2 calculates the sum of the two numbers stored in nNum1 and nNum2, and assigns the result to the variable nSum.
  8. DISPLAY "SUM OF THESE NUMBER : " nSum prints the string “SUM OF THESE NUMBER :” and the value of the nSum variable.
  9. END is a marker that indicates the end of the program.

This pseudocode prompts the user to enter two numbers and then adds them. The sum is then stored in nSum variable and the program then prints the sum. The program follows the basic flow of input, computation and output.

Example 3: WRITE A PSEUDOCODE TO FIND THE SUM OF THREE NUMBERS.

The above block of text is a pseudocode that prompts the user to enter three numbers and then calculates and displays their sum. Here is an explanation of each line:

  1. BEGIN is a marker that indicates the start of the program.
  2. NUMERIC nNum1,nNum2,nNum3,nSum declares four variables, nNum1, nNum2, nNum3 and nSum, as numeric data types.
  3. DISPLAY "ENTER THE FIRST NUMBER : " prints the string “ENTER THE FIRST NUMBER :” to the screen.
  4. ACCEPT nNum1 waits for the user to enter a value, which is then stored in the variable nNum1.
  5. DISPLAY "ENTER THE SECOND NUMBER : " prints the string “ENTER THE SECOND NUMBER :” to the screen.
  6. ACCEPT nNum2 waits for the user to enter a value, which is then stored in the variable nNum2.
  7. DISPLAY "ENTER THE THIRD NUMBER : " prints the string “ENTER THE THIRD NUMBER :” to the screen.
  8. ACCEPT nNum3 waits for the user to enter a value, which is then stored in the variable nNum3.
  9. nSum=nNum1+nNum2+nNum3 calculates the sum of all three numbers, nNum1, nNum2 and nNum3 and assigns the result to the variable nSum.
  10. DISPLAY "SUM OF ALL THREE NUMBERS : " nSum prints the string “SUM OF ALL THREE NUMBERS :” and the value of the nSum variable.
  11. END is a marker that indicates the end of the program.

This pseudocode prompts the user to enter three numbers and then adds them all together. The sum is then stored in nSum variable and the program then prints the sum. The program follows the basic flow of input, computation and output.

Example 4: WRITE A PSEUDOCODE TO FIND THE AREA OF RECTANGLE.

The above block of text is a pseudocode that calculates the area of a rectangle by prompt the user to enter the length and breadth of the rectangle and then calculates and display the area. Here is an explanation of each line:

  1. BEGIN is a marker that indicates the start of the program.
  2. NUMERIC nLen,nBrd,nAre declares three variables, nLen, nBrd, and nAre, as numeric data types.
  3. DISPLAY "ENTER THE LENGTH OF RECTANGLE : " prints the string “ENTER THE LENGTH OF RECTANGLE :” to the screen.
  4. ACCEPT nLen waits for the user to enter a value, which is then stored in the variable nLen.
  5. DISPLAY "ENTER THE BREADTH OF RECTANGLE : " prints the string “ENTER THE BREADTH OF RECTANGLE :” to the screen.
  6. ACCEPT nBrd waits for the user to enter a value, which is then stored in the variable nBrd.
  7. nAre=nLen*nBrd calculates the area of the rectangle by multiplying the value of nLen and nBrd and assigns the result to the variable nAre.
  8. DISPLAY "AREA OF RECTANGLE : " nAre prints the string “AREA OF RECTANGLE :” and the value of the nAre variable.
  9. END is a marker that indicates the end of the program.

This pseudocode prompts the user to enter the length and breadth of a rectangle and then calculates the area by multiplying them. The area is then stored in the nAre variable and the program then prints the area. The program follows the basic flow of input, computation and output.

Example 5: WRITE A PSEUDOCODE TO FIND THE PERIMETER OF RECTANGLE.

The above block of text is a pseudocode that calculates the perimeter of a rectangle by prompting the user to enter the length and breadth of the rectangle and then calculates and displays the perimeter. Here is an explanation of each line:

  1. BEGIN is a marker that indicates the start of the program.
  2. NUMERIC nLen,nBrd,nAre declares three variables, nLen, nBrd, and nAre, as numeric data types.
  3. DISPLAY "ENTER THE LENGTH OF RECTANGLE : " prints the string “ENTER THE LENGTH OF RECTANGLE :” to the screen.
  4. ACCEPT nLen waits for the user to enter a value, which is then stored in the variable nLen.
  5. DISPLAY "ENTER THE BREADTH OF RECTANGLE : " prints the string “ENTER THE BREADTH OF RECTANGLE :” to the screen.
  6. ACCEPT nBrd waits for the user to enter a value, which is then stored in the variable nBrd.
  7. nAre=2*(nLen+nBrd) calculates the perimeter of the rectangle by multiplying 2 with the sum of nLen and nBrd, and assigns the result to the variable nAre.
  8. DISPLAY "PERIMETER OF RECTANGLE : " nAre prints the string “PERIMETER OF RECTANGLE :” and the value of the nAre variable.
  9. END is a marker that indicates the end of the program.

This pseudocode prompts the user to enter the length and breadth of a rectangle and then calculates the perimeter by 2*(nLen+nBrd) . The perimeter is then stored in the nAre variable, but it should be named nPerimeter for clarity, and the program then prints the perimeter . The program follows the basic flow of input, computation and output.

Example 6: WRITE A PSEUDOCODE TO FIND THE AREA OF SQUARE.

The above block of text is a pseudocode that calculates the area of a square by prompting the user to enter the length of one side of the square and then calculates and displays the area. Here is an explanation of each line:

  1. BEGIN is a marker that indicates the start of the program.
  2. NUMERIC nSide, nArea declares two variables, nSide, and nArea, as numeric data types.
  3. DISPLAY "ENTER THE SIDE OF SQUARE : " prints the string “ENTER THE SIDE OF SQUARE :” to the screen.
  4. ACCEPT nSide waits for the user to enter a value, which is then stored in the variable nSide.
  5. nArea=nSide*nSide calculates the area of the square by multiplying the value of nSide with itself and assigns the result to the variable nArea.
  6. DISPLAY "AREA OF SQUARE : " nArea prints the string “AREA OF SQUARE :” and the value of the nArea variable.
  7. END is a marker that indicates the end of the program.

This pseudocode prompts the user to enter one side of a square and then calculates the area by squaring the side. The area is then stored in the nArea variable and the program then prints the area. The program follows the basic flow of input, computation and output.

Example 7: WRITE A PSEUDOCODE TO FIND THE PERIMETER OF SQUARE.

The above block of text is a pseudocode that calculates the area of a square by prompting the user to enter the length of one side of the square, but it is incorrectly displaying the result as the perimeter of the square. Here is an explanation of each line:

  1. BEGIN is a marker that indicates the start of the program.
  2. NUMERIC nSide, nPeri declares two variables, nSide, and nPeri, as numeric data types.
  3. DISPLAY "ENTER THE SIDE OF SQUARE : " prints the string “ENTER THE SIDE OF SQUARE :” to the screen.
  4. ACCEPT nSide waits for the user to enter a value, which is then stored in the variable nSide.
  5. nPeri=nSide*nSide calculates the area of the square by multiplying the value of nSide with itself and assigns the result to the variable nPeri.
  6. DISPLAY "AREA OF SQUARE : " nPeri prints the string “AREA OF SQUARE :” and the value of the nPeri variable, which should be labeled as nArea.
  7. END is a marker that indicates the end of the program.

This pseudocode is not correctly calculating the perimeter of square, it’s just multiplying the side with itself and it incorrectly calls the result as the area of the square.

Example 8: WRITE A PSEUDOCODE TO FIND THE AREA OF CIRCLE.

The above block of text is a pseudocode that calculates the area of a circle by prompting the user to enter the radius of the circle, and then calculates and displays the area. Here is an explanation of each line:

  1. BEGIN is a marker that indicates the start of the program.
  2. NUMERIC nRad, nArea declares two variables, nRad, and nArea, as numeric data types.
  3. DISPLAY "ENTER THE RADIUS OF CIRCLE : " prints the string “ENTER THE RADIUS OF CIRCLE :” to the screen.
  4. ACCEPT nRad waits for the user to enter a value, which is then stored in the variable nRad.
  5. nArea = nRad*nRad*22/7 calculates the area of the circle by multiplying the value of nRad with itself, and multiplying with the approximation value of π(22/7), and assigns the result to the variable nArea.
  6. DISPLAY "AREA OF CIRCLE : " nArea prints the string “AREA OF CIRCLE :” and the value of the nArea variable.
  7. END is a marker that indicates the end of the program.

This pseudocode prompts the user to enter the radius of a circle and then calculates the area by using the formula nArea = nRad * nRad * π, where nArea is the area of the circle, nRad is the radius of the circle and π is the mathematical constant. In this case, π has been approximated to 22/7, so the final formula used is nArea = nRad * nRad * 22/7. It should be noted that this approximation of π to 22/7 is not accurate, if you need more precision in your calculation, it’s suggested to use the built-in constant for π in the programming language of your choice or use more accurate value of π. It’s also good to name variable and function as per their intended use to make it more readable.

Example 9: WRITE A PSEUDOCODE TO FIND THE CIRCUMFERENCE OF CIRCLE.

The above block of text is a pseudocode that calculates the circumference of a circle by prompting the user to enter the radius of the circle, and then calculates and displays the circumference. Here is an explanation of each line:

  1. BEGIN is a marker that indicates the start of the program.
  2. NUMERIC nRad,nCir declares two variables, nRad and nCir, as numeric data types.
  3. DISPLAY "ENTER THE RADIUS OF CIRCLE : " prints the string “ENTER THE RADIUS OF CIRCLE :” to the screen.
  4. ACCEPT nRad waits for the user to enter a value, which is then stored in the variable nRad.
  5. nCir=2*nRad*22/7 calculates the circumference of the circle by multiplying the value of 2 with the value of nRad, multiplying with the approximation value of π(22/7), and assigns the result to the variable nCir.
  6. DISPLAY "CIRCUMFERENCE OF CIRCLE : " nCir prints the string “CIRCUMFERENCE OF CIRCLE :” and the value of the nCir variable.
  7. END is a marker that indicates the end of the program.

This pseudocode prompts the user to enter the radius of a circle and then calculates the circumference by using the formula nCir = 2 * nRad * π, where nCir is the circumference of the circle, nRad is the radius of the circle and π is the mathematical constant. In this case, π has been approximated to 22/7, so the final formula used is nCir = 2 * nRad * 22/7. As i have mentioned earlier,this approximation of π to 22/7 is not accurate, if you need more precision in your calculation, it’s suggested to use the built-in constant for π in the programming language of your choice or use more accurate value of π. It’s also good to name variable and function as per their intended use to make it more readable.

Example 10: WRITE A PSEUDOCODE TO FIND THE AREA OF PARALLELOGRAM.

The above block of text is a pseudocode that calculates the area of a parallelogram by prompting the user to enter the base and the height, and then calculates and displays the area. Here is an explanation of each line:

  1. BEGIN is a marker that indicates the start of the program.
  2. NUMERIC nBase, nPerp, nArea declares three variables, nBase, nPerp, and nArea, as numeric data types.
  3. DISPLAY "ENTER THE BASE : " prints the string “ENTER THE BASE :” to the screen.
  4. ACCEPT nBase waits for the user to enter a value, which is then stored in the variable nBase.
  5. DISPLAY "ENTER THE PERPENDICULAR : " prints the string “ENTER THE PERPENDICULAR :” to the screen.
  6. ACCEPT nPerp waits for the user to enter a value, which is then stored in the variable nPerp.
  7. nArea=nBase*nPerp calculates the area of the parallelogram by multiplying the value of nBase with the value of nPerp, and assigns the result to the variable nArea.
  8. DISPLAY "AREA OF PARALLELOGRAM : " nArea prints the string “AREA OF PARALLELOGRAM :” and the value of the nArea variable.
  9. END is a marker that indicates the end of the program.

This pseudocode prompts the user to enter the base and height of a parallelogram and then calculates the area by multiplying the base and height. The area is then stored in the nArea variable and the program then prints the area.

The program follows the basic flow of input, computation and output.It’s also good to name variable and function as per their intended use to make it more readable.

Example 11: WRITE A PSEUDOCODE TO FIND THE AREA OF TRIANGLE.

This piece of pseudocode calculates the area of a triangle. It starts by declaring three variables: nBase, nHigh, and nArea. These variables are used to store the base and height of the triangle, as well as the calculated area.

The program then prompts the user to enter the base and height of the triangle, by displaying the messages “ENTER THE BASE OF TRIANGLE : ” and “ENTER THE HEIGHT OF TRIANGLE : ” respectively. The input values are then stored in the nBase and nHigh variables.

The program then calculates the area of the triangle by multiplying the value stored in the nBase variable by the value stored in the nHigh variable. The result is stored in the nArea variable.

Finally, the program displays the message “AREA OF TRIANGLE : ” followed by the value stored in the nArea variable. This displays the calculated area of the triangle to the user.

It’s worth noting that this pseudocode does not include any error handling mechanism in case the user inputs non-numeric value, it will cause the program to crash. Additionally, the program does not include any mechanism for ensuring that the input is a positive value, which could lead to calculating the area of a triangle with negative values.

Example 12: WRITE A PSEUDOCODE TO FIND THE  AREA OF RHOMBUS.

This piece of pseudocode calculates the area of a rhombus. A rhombus is a type of parallelogram that has opposite sides that are congruent and parallel, and its diagonals bisect each other at right angles. The area of a rhombus can be calculated by multiplying the length of one diagonal by the length of the other diagonal and then dividing the result by 2.

The program starts by declaring three variables: nDgn1, nDgn2 and nArea. These variables are used to store the length of the first diagonal, the length of the second diagonal, and the calculated area of the rhombus.

The program then prompts the user to enter the length of the first diagonal and the second diagonal by displaying the messages “ENTER THE LENGTH OF FIRST DIAGONAL : ” and “ENTER THE LENGTH OF SECOND DIAGONAL : ” respectively. The input values are then stored in the nDgn1 and nDgn2 variables.

The program then calculates the area of the rhombus by multiplying the value stored in the nDgn1 variable by the value stored in the nDgn2 variable and then dividing by 2. The result is stored in the nArea variable.

Finally, the program displays the message “AREA OF RHOMBUS : ” followed by the value stored in the nArea variable. This displays the calculated area of the rhombus to the user.

As before, this pseudocode does not include any error handling mechanism in case the user inputs non-numeric value, it will cause the program to crash. Additionally, the program does not include any mechanism for ensuring that the input is a positive value, which could lead to calculating the area of a rhombus with negative values.

Example 13: WRITE A PSEUDOCODE TO FIND THE GREATEST OF TWO NUMBERS.

This pseudocode prompts the user to enter two numbers, nNum1 and nNum2, and then compares them to determine which is the greater number.

BEGIN is a marker that indicates the start of the program.

NUMERIC nNum1, nNum2 declares two variables, nNum1 and nNum2, as numeric data types.

DISPLAY “ENTER THE FIRST NUMBER : ” prints the string “ENTER THE FIRST NUMBER :” to the screen.

ACCEPT nNum1 waits for the user to enter a value, which is then stored in the variable nNum1.

DISPLAY “ENTER THE SECOND NUMBER : ” prints the string “ENTER THE SECOND NUMBER :” to the screen.

ACCEPT nNum2 waits for the user to enter a value, which is then stored in the variable nNum2.

IF(nNum1>nNum2) is a conditional statement that checks if nNum1 is greater than nNum2. If it is, the code block within the IF statement will be executed.

BEGIN starts the code block that is executed if nNum1 is greater than nNum2.

DISPLAY “GREATEST ONE : ” nNum1 prints the string “GREATEST ONE : ” and the value of the nNum1 variable.

END is a marker that indicates the end of the code block within the IF statement.

ELSE starts the code block that is executed if nNum1 is not greater than nNum2.

BEGIN starts the code block within the ELSE statement.

DISPLAY “GREATEST ONE : ” nNum2 prints the string “GREATEST ONE : ” and the value of the nNum2 variable.

END is a marker that indicates the end of the code block within the ELSE statement.

END is a marker that indicates the end of the program.

Overall, this pseudocode prompts the user to enter two numbers, compares them to determine which is greater, and then prints the greatest number. The program follows the basic flow of input, computation, and output.

Example 14: WRITE A PSEUDOCODE TO FIND THE GREATEST OF TWO NUMBERS USING TERNARY OPERATOR.

This pseudocode is similar to the previous one, but it uses a ternary operator ( ?: ) to determine the greater number and assigns it to the variable nGone.

BEGIN is a marker that indicates the start of the program.

NUMERIC nNum1, nNum2 declares two variables, nNum1 and nNum2, as numeric data types.

DISPLAY “ENTER THE FIRST NUMBER : ” prints the string “ENTER THE FIRST NUMBER :” to the screen.

ACCEPT nNum1 waits for the user to enter a value, which is then stored in the variable nNum1.

DISPLAY “ENTER THE SECOND NUMBER : ” prints the string “ENTER THE SECOND NUMBER :” to the screen.

ACCEPT nNum2 waits for the user to enter a value, which is then stored in the variable nNum2.

nGone=(nNum1>nNum2)?nNum1:nNum2 uses the ternary operator ( ?: ) to check if nNum1 is greater than nNum2. If it is, nNum1 is assigned to nGone, otherwise nNum2 is assigned to nGone.

DISPLAY “GREATEST ONE : ” nGone prints the string “GREATEST ONE : ” and the value of the nGone variable, which will be the greater of nNum1 and nNum2.

END is a marker that indicates the end of the program.

Overall, this pseudocode prompts the user to enter two numbers, uses a ternary operator to determine the greater number and assigns it to the variable nGone, and then prints the greatest number. The program follows the basic flow of input, computation, and output. And this is a more concise way to determine the greater number and assign it to a variable.

Example 15: WRITE A PSEUDOCODE TO FIND THE GREATEST OF THREE NUMBERS.

This pseudocode prompts the user to enter three numbers, nNum1, nNum2, and nNum3, and then uses nested if-else statements to determine the greatest number among them.

BEGIN is a marker that indicates the start of the program.

NUMERIC nNum1,nNum2,nNum3 declares three variables, nNum1, nNum2, and nNum3, as numeric data types.

DISPLAY “ENTER THE FIRST NUMBER : ” prints the string “ENTER THE FIRST NUMBER :” to the screen.

ACCEPT nNum1 waits for the user to enter a value, which is then stored in the variable nNum1.

DISPLAY “ENTER THE SECOND NUMBER : ” prints the string “ENTER THE SECOND NUMBER :” to the screen.

ACCEPT nNum2 waits for the user to enter a value, which is then stored in the variable nNum2.

DISPLAY “ENTER THE THIRD NUMBER : ” prints the string “ENTER THE THIRD NUMBER :” to the screen.

ACCEPT nNum3 waits for the user to enter a value, which is then stored in the variable nNum3.

IF(nNum1>nNum2) is a conditional statement that checks if nNum1 is greater than nNum2. If it is, the code block within the IF statement will be executed.

BEGIN starts the code block that is executed if nNum1 is greater than nNum2.

IF(nNum1>nNum3) is a nested conditional statement that checks if nNum1 is also greater than nNum3. If it is, the code block within the nested IF statement will be executed.

BEGIN starts the code block that is executed if nNum1 is greater than nNum3.

DISPLAY “GREATEST ONE : ” nNum1 prints the string “GREATEST ONE : ” and the value of the nNum1 variable.

END is a marker that indicates the end of the code block within the nested IF statement.

ELSE starts the code block that is executed if nNum1 is not greater than nNum3.

BEGIN starts the code block within the ELSE statement.

DISPLAY “GREATEST ONE : ” nNum3 prints the string “GREATEST ONE : ” and the value of the nNum3 variable.

END is a marker that indicates the end of the code block within the ELSE statement.

END is a marker that indicates the end of the code block within the IF statement.

ELSE starts the code block that is executed if nNum1 is not greater than nNum2.

IF(nNum2>nNum3) is a nested conditional statement that checks if nNum2 is greater than nNum3. If it is, the code block within the nested IF statement will be executed.

BEGIN starts the code block that is executed if nNum2 is greater than nNum3.

DISPLAY “GREATEST ONE : ” nNum2 prints the string “GREATEST ONE : ” and the value of the nNum2 variable.

END is a marker that indicates the end of the code block within the nested IF statement.

ELSE starts the code block that is executed if nNum2 is not greater than nNum3.

BEGIN starts the code block within the ELSE statement.

DISPLAY “GREATEST ONE : ” nNum3 prints the string “GREATEST ONE : ” and the value of the nNum3 variable.

END is a marker that indicates the end of the code block within the ELSE statement.

END is a marker that indicates the end of the program.

Overall, this pseudocode prompts the user to enter three numbers, nNum1, nNum2, and nNum3, and then uses nested if-else statements to determine the greatest number among them. It compares the three numbers in a series of nested if-else statements to find the greatest number and finally display it. The program follows the basic flow of input, computation, and output.

It’s important to note that this pseudocode is longer and more complex than the previous ones because it uses nested if-else statements to compare three numbers instead of just two. Also, it could use more variable names for better readability.

Example 16: WRITE A PSEUDOCODE TO FIND THE GREATEST OF THREE NUMBERS.

Example 17: WRITE A PSEUDOCODE TO FIND THE GREATEST OF THREE NUMBERS.

Example 18: WRITE A PSEUDOCODE TO CHECK WHETHER THE ENTERED NUMBER IS EVEN OR ODD.

Example 19: WRITE A PSEUDOCODE TO CHECK EQUIVALENCE OF TWO NUMBERS. USE IF STATEMENT.

Example 20: WRITE A PSEUDOCODE TO FIND THE SMALLEST OUT OF THREE NUMBERS.,

Example 21: WRITE A PSEUDOCODE TO CHECK WHETHER THE ENTERED YEAR IS A LEAP YEAR OR NOT.

Example 22: WRITE A PSEUDOCODE TO DISPLAY THE NAMES OF THE DAYS OF A WEEK.

Example 23: WRITE A PSEUDOCODE TO DISPLAY MONTH NAME ACCORDING TO THEIR POSITION.

Example 24: WRITE A PSEUDOCODE TO DISPLAY THE STUDENT NAME ACCORDING TO THEIR ROLL NO.

Example 25: WRITE A PSEUDOCODE TO PRINT THE FIRST FIVE NUMBERS.

Example 26: WRITE A PSEUDOCODE TO DISPLAY NUMBERS FROM 1 TO 15 USING FOR LOOP.

Example 27: WRITE A PSEUDOCODE TO DISPLAY EVEN NUMBERS FROM 1 TO 14.

Example 28: WRITE A PSEUDOCODE TO DISPLAY UPTO INTEGERS UPTO N.

Example 29: WRITE A PSEUDOCODE TO DISPLAY ALL EVEN NUMBERS UPTO N.

Example 30: WRITE A PSEUDOCODE TO DISPLAY ALL ODD NUMBERS UPTO N.

Example 31: WRITE A PSEUDOCODE TO FIND THE SUM OF SERIES S=1+2+3+….. +N

Example 32: WRITE A PSEUDOCODE TO FIND THE SUM OF SERIES S=1+3+5+…. +N

Example 33: WRITE A PSEUDOCODE TO PRINT THE ALL EVEN BETWEEN 2 AND 100.

Example 34: WRITE A PSEUDOCODE TO PRINT THE INTERGERS 1 TO N USING while LOOP.

Example 35: WRITE A PSEUDOCODE TO PRINT THE ALL EVEN NUMBERS FROM 1 TO N USING while LOOP.

Example 36: WRITE A PSEUDOCODE TO PRINT THE ALL ODD NUMBERS FROM 1 TO N USING while LOOP.

Example 37: WRITE A PSEUDOCODE TO FIND THE SUM OF SERIES S=1+2+3+…….+N

Example 38: WRITE A PSEUDOCODE TO FIND THE SUM OF SERIES S=1+3+5+……+N

Example 39: WRITE A PSEUDOCODE TO PRINT THE NUMBERS FROM 1 TO N USING do….while LOOP

Example 40: WRITE A PSEUDOCODE TO PRINT ALL EVEN NUMBERS FROM 2 TO N.

Example 41: WRITE A PSEUDOCODE TO PRINT ALL ODD NUMBERS FROM 1 TO N.

Example 42: WRITE A PSEUDOCODE TO PRINT THE SUM OF SERIES S=1+2+3+….+N

5 Comments

  • from sympy import *
    x, y = symbols(‘x y’)
    # exp = x**7+y**5
    # print(type(exp))
    exp = eval(input(“Enter your function: “))
    diff_pt_x = input(“Enter the value of point ‘x’: “)
    diff_pt_y = input(“Enter the value of point ‘y’: “)
    f_0 = exp.subs([(x, diff_pt_x), (y, diff_pt_y)])
    f_1 = (x-int(diff_pt_x))*diff(exp, x).subs([(x, diff_pt_x), (y, diff_pt_y)])
    f_2 = (y-int(diff_pt_y))*diff(exp, y).subs([(x, diff_pt_x), (y, diff_pt_y)])
    linear_f = f_0 + f_1 + f_2
    print(linear_f)

    d1 = float(input(“Enter the value: “))
    d2 = float(input(“Enter the value: “))
    f_x = diff(exp, x)
    f_y = diff(exp, y)
    f_xx = diff(f_x, x)
    f_yy = diff(f_y, y)
    f_xy = diff(f_x, y)
    max_error = ((max(f_xx, f_yy, f_xy))/2)+(d1+d2)**2
    print(max_error)
    can u write pseudo code for this

    • Solution 1:
      def taylor_approximation(exp, diff_pt_x, diff_pt_y):
      f_0 = evaluate exp at x=diff_pt_x and y=diff_pt_y
      f_1 = (x-diff_pt_x) * derivative of exp with respect to x at x=diff_pt_x and y=diff_pt_y
      f_2 = (y-diff_pt_y) * derivative of exp with respect to y at x=diff_pt_x and y=diff_pt_y
      linear_f = f_0 + f_1 + f_2
      return linear_f

      def maximum_error(exp, diff_pt_x, diff_pt_y, d1, d2):
      f_x = derivative of exp with respect to x at x=diff_pt_x and y=diff_pt_y
      f_y = derivative of exp with respect to y at x=diff_pt_x and y=diff_pt_y
      f_xx = second derivative of exp with respect to x at x=diff_pt_x and y=diff_pt_y
      f_yy = second derivative of exp with respect to y at x=diff_pt_x and y=diff_pt_y
      f_xy = second derivative of exp with respect to x and y at x=diff_pt_x and y=diff_pt_y
      max_error = ((max(f_xx, f_yy, f_xy))/2) + (d1+d2)**2
      return max_error

      Solution 2:
      import sympy

      # Define symbols x and y
      x, y = symbols(‘x y’)

      # Get the expression from the user
      exp_str = input(“Enter your function: “)
      exp = eval(exp_str)

      # Get the values of x and y at the point of differentiation
      diff_pt_x = input(“Enter the value of point ‘x’: “)
      diff_pt_y = input(“Enter the value of point ‘y’: “)

      # Calculate the linear approximation of the function at the given point
      f_0 = exp.subs([(x, diff_pt_x), (y, diff_pt_y)])
      f_1 = (x-int(diff_pt_x))*diff(exp, x).subs([(x, diff_pt_x), (y, diff_pt_y)])
      f_2 = (y-int(diff_pt_y))*diff(exp, y).subs([(x, diff_pt_x), (y, diff_pt_y)])
      linear_f = f_0 + f_1 + f_2
      print(linear_f)

      # Get values for d1 and d2
      d1 = float(input(“Enter the value: “))
      d2 = float(input(“Enter the value: “))

      # Calculate the second partial derivatives of the function
      f_x = diff(exp, x)
      f_y = diff(exp, y)
      f_xx = diff(f_x, x)
      f_yy = diff(f_y, y)
      f_xy = diff(f_x, y)

      # Calculate the maximum error of the linear approximation
      max_error = ((max(f_xx, f_yy, f_xy))/2)+(d1+d2)**2
      print(max_error)

      Solution 3:
      here’s the pseudo-code for the given code snippet:

      Import the symbols function from sympy
      Define the variables x and y using the symbols function
      Evaluate the input function and store it in a variable exp
      Get the value of x and y at a specific point from the user
      Substitute the values of x and y obtained from the user into the expression exp and store the result in a variable f_0
      Calculate f_1 using the diff function and the expression for x and y obtained from the user
      Calculate f_2 using the diff function and the expression for x and y obtained from the user
      Calculate the linear approximation of the function using f_0, f_1, and f_2 and store it in a variable linear_f
      Print linear_f
      Get values of d1 and d2 from the user
      Calculate the partial derivatives of exp with respect to x and y, and the second partial derivative of exp with respect to x and y
      Calculate the maximum error using the partial derivatives and d1 and d2
      Print the maximum error

  • Most of your examples are NOT pseudocode. Pseudocode is written in plain English. Your examples appear to be code. As per your rule “Write what you mean, not how to program it,” there shouldn’t be any reference to actual code.

Leave a Comment