Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Algorithms
  • Analysis of Algorithms
  • Sorting
  • Searching
  • Greedy
  • Recursion
  • Backtracking
  • Dynamic Programming
  • Divide and Conquer
  • Geometric Algorithms
  • Mathematical Algorithms
  • Pattern Searching
  • Bitwise Algorithms
  • Branch & Bound
  • Randomized Algorithms
Open In App
Next Article:
How Does Solidity Works?
Next article icon

How to write a Pseudo Code?

Last Updated : 23 Nov, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Pseudo code is a term which is often used in programming and algorithm based fields. It is a methodology that allows the programmer to represent the implementation of an algorithm. Simply, we can say that it’s the cooked up representation of an algorithm. Often at times, algorithms are represented with the help of pseudo codes as they can be interpreted by programmers no matter what their programming background or knowledge is. Pseudo code, as the name suggests, is a false code or a representation of code which can be understood by even a layman with some school level programming knowledge. Algorithm: It’s an organized logical sequence of the actions or the approach towards a particular problem. A programmer implements an algorithm to solve a problem. Algorithms are expressed using natural verbal but somewhat technical annotations. Pseudo code: It’s simply an implementation of an algorithm in the form of annotations and informative text written in plain English. It has no syntax like any of the programming language and thus can’t be compiled or interpreted by the computer.

Advantages of Pseudocode

  • Improves the readability of any approach. It’s one of the best approaches to start implementation of an algorithm.
  • Acts as a bridge between the program and the algorithm or flowchart. Also works as a rough documentation, so the program of one developer can be understood easily when a pseudo code is written out. In industries, the approach of documentation is essential. And that’s where a pseudo-code proves vital.
  • The main goal of a pseudo code is to explain what exactly each line of a program should do, hence making the code construction phase easier for the programmer.

How to write a Pseudo-code?

  1. Arrange the sequence of tasks and write the pseudocode accordingly.
  2. Start with the statement of a pseudo code which establishes the main goal or the aim. Example:
This program will allow the user to check
the number whether it's even or odd.

  1. The way the if-else, for, while loops are indented in a program, indent the statements likewise, as it helps to comprehend the decision control and execution mechanism. They also improve the readability to a great extent.
Example:
if "1"
print response
"I am case 1"
if "2"
print response
"I am case 2"

  1. Use appropriate naming conventions. The human tendency follows the approach to follow what we see. If a programmer goes through a pseudo code, his approach will be the same as per it, so the naming must be simple and distinct.
  2. Use appropriate sentence casings, such as CamelCase for methods, upper case for constants and lower case for variables.
  3. Elaborate everything which is going to happen in the actual code. Don’t make the pseudo code abstract.
  4. Use standard programming structures such as ‘if-then’, ‘for’, ‘while’, ‘cases’ the way we use it in programming.
  5. Check whether all the sections of a pseudo code is complete, finite and clear to understand and comprehend.
  6. Don’t write the pseudo code in a complete programmatic manner. It is necessary to be simple to understand even for a layman or client, hence don’t incorporate too many technical terms.
 Dos and Don'ts in  Pseudo Code Writing

Dos and Don’ts to Pseudo Code Writing

Example:

Let’s have a look at this code 

C++




#include <iostream>
 
long long gcd(long long numberOne, long long numberTwo) {
    if (numberTwo == 0)
        return numberOne;
 
    return gcd(numberTwo, numberOne % numberTwo);
}
 
long long lcmNaive(long long numberOne, long long numberTwo) {
    long long lowestCommonMultiple = (numberOne * numberTwo) / gcd(numberOne, numberTwo);
    return lowestCommonMultiple;
}
 
int main() {
    std::cout << "Enter the inputs" << std::endl;
    long long numberOne, numberTwo;
    std::cin >> numberOne >> numberTwo;
 
    std::cout << lcmNaive(numberOne, numberTwo) << std::endl;
 
    return 0;
}
 
 

Java




// This program calculates the Lowest Common multiple
// for excessively long input values
 
import java.util.*;
 
public class LowestCommonMultiple {
 
    private static long
    lcmNaive(long numberOne, long numberTwo)
    {
 
        long lowestCommonMultiple;
 
        lowestCommonMultiple
            = (numberOne * numberTwo)
              / greatestCommonDivisor(numberOne,
                                      numberTwo);
 
        return lowestCommonMultiple;
    }
 
    private static long
    greatestCommonDivisor(long numberOne, long numberTwo)
    {
 
        if (numberTwo == 0)
            return numberOne;
 
        return greatestCommonDivisor(numberTwo,
                                     numberOne % numberTwo);
    }
    public static void main(String args[])
    {
 
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter the inputs");
        long numberOne = scanner.nextInt();
        long numberTwo = scanner.nextInt();
 
        System.out.println(lcmNaive(numberOne, numberTwo));
    }
}
 
 

Python




def gcd(numberOne, numberTwo):
    if numberTwo == 0:
        return numberOne
    return gcd(numberTwo, numberOne % numberTwo)
 
 
def lcmNaive(numberOne, numberTwo):
    lowestCommonMutliple = (numberOne * numberTwo) / gcd(numberOne, numberTwo)
    return lowestCommonMutliple
# This Code is Contributed by Chandrashekhar Robbi
 
numberOne = 5
numberTwo = 2
 
print(lcmNaive(numberOne, numberTwo))
 
 

C#




// This program calculates the Lowest Common multiple
// for excessively long input values
using System;
 
public class LowestCommonMultiple {
 
private static long
lcmNaive(long numberOne, long numberTwo)
{
 
    long lowestCommonMultiple;
 
    lowestCommonMultiple
        = (numberOne * numberTwo)
        / greatestCommonDivisor(numberOne,
                                numberTwo);
 
    return lowestCommonMultiple;
}
 
    private static long greatestCommonDivisor(long numberOne, long numberTwo)
    {
     
        if (numberTwo == 0)
            return numberOne;
     
        return greatestCommonDivisor(numberTwo,numberOne % numberTwo);
    }
    // Drive code
    public static void Main()
    {
     
        Console.WriteLine("Enter the inputs");
        long numberOne = Convert.ToInt64(Console.ReadLine());
        long numberTwo = Convert.ToInt64(Console.ReadLine());
     
        Console.WriteLine(lcmNaive(numberOne, numberTwo));
    }
}
 
// This code is contriburte by shiv1o43g
 
 

Javascript




// Function to calculate the Greatest Common Divisor
function gcd(numberOne, numberTwo) {
    if (numberTwo === 0) {
        return numberOne;
    }
    return gcd(numberTwo, numberOne % numberTwo);
}
 
// Function to calculate the Lowest Common Multiple
function lcmNaive(numberOne, numberTwo) {
    // Calculate LCM using the formula: LCM(a, b) = (a * b) / GCD(a, b)
    return (numberOne * numberTwo) / gcd(numberOne, numberTwo);
}
 
// Given inputs
const numberOne = 5;
const numberTwo = 2;
 
// Calculate and display the Lowest Common Multiple
console.log('Lowest Common Multiple:', lcmNaive(numberOne, numberTwo));
 
 


Next Article
How Does Solidity Works?
author
theprogrammedwords
Improve
Article Tags :
  • Advanced Data Structure
  • Algorithms
  • Computer Subject
  • DSA
  • Algorithms-Misc
Practice Tags :
  • Advanced Data Structure
  • Algorithms

Similar Reads

  • What is PseudoCode: A Complete Tutorial
    A Pseudocode is defined as a step-by-step description of an algorithm. Pseudocode does not use any programming language in its representation instead it uses the simple English language text as it is intended for human understanding rather than machine reading.Pseudocode is the intermediate state be
    15 min read
  • How Does Solidity Works?
    Solidity is a programming language that helps developers create special programs called smart contracts. These contracts are used on the Ethereum blockchain, Which is like a giant computer that runs Decentralized Applications (DApps). In this article, We will explain how Solidity works in a simple w
    6 min read
  • How to Code in R programming?
    R is a powerful programming language and environment for statistical computing and graphics. Whether you're a data scientist, statistician, researcher, or enthusiast, learning R programming opens up a world of possibilities for data analysis, visualization, and modeling. This comprehensive guide aim
    4 min read
  • What is a Code in Programming?
    In programming, "code" refers to a set of instructions or commands written in a programming language that a computer can understand and execute. In this article, we will learn about the basics of Code, types of Codes and difference between Code, Program, Script, etc. Table of Content What is Code?Co
    10 min read
  • Flow Graph in Code Generation
    A basic block is a simple combination of statements. Except for entry and exit, the basic blocks do not have any branches like in and out. It means that the flow of control enters at the beginning and it always leaves at the end without any halt. The execution of a set of instructions of a basic blo
    4 min read
  • What Is Coding and What Is It Used For?
    Coding is the process of designing and building executable computer programs to accomplish a specific task or solve a problem. It involves writing sets of instructions in a programming language that a computer can understand and execute. Coding is a fundamental skill in the field of computer science
    6 min read
  • How to Use Algorithms to Solve Problems?
    An algorithm is a process or set of rules which must be followed to complete a particular task. This is basically the step-by-step procedure to complete any task. All the tasks are followed a particular algorithm, from making a cup of tea to make high scalable software. This is the way to divide a t
    4 min read
  • Simple Code Generator
    Compiler Design is an important component of compiler construction. It involves many different tasks, such as analyzing the source code and producing an intermediate representation (IR) from it, performing optimizations on the IR to produce a target machine code, and generating external representati
    7 min read
  • Morse Code Implementation
    Morse code is a method of transmitting text information as a series of on-off tones, lights, or clicks that can be directly understood by a skilled listener or observer without special equipment. It is named for Samuel F. B. Morse, an inventor of the telegraph. The algorithm is very simple. Every ch
    9 min read
  • What is a Computer Program?
    Software development is one of the fastest-growing technologies as it can make work easy in our daily lives. It is the foundation of modern technology. We write a set of programs to form software programs is the basic necessity for building software. Here in this article, we are going to learn about
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences