Pseudo Code

Share

```
Main()
Begin
Print: “Hello World”;
End
```

```
/*
name is a variable used to store the name entered by user
*/
Main()
Begin
Read: name;
Print: “Hi ”, name;
End
```

Note! Message “Hi” and variable name is separated by comma ,

```
/*
x and y will store the input and
sum will store the result
*/
SumOf2Num()
Begin
Read: x, y;
Set sum = x + y;
Print: sum;
End
```

```
Print1To10()
Begin
for i = 1 to 10 by 1 do
Print: i and go to new line;
endfor
End
```

Note! You can use small sentences like “go to new line” in your instruction

```
/*
Even no. between 1 to 100 starts from 2 and goes up to 100.
So we’ll use a for loop,
start it from 2 and increment i by 2 till we reach 100
*/
PrintEven()
Begin
for i = 2 to 100 by 2 do
Print: i and go to new line;
endfor
End
```

```
/*
Odd no. between 1 to 100 starts from 1 and goes up to 99. So we’ll use a for loop, start it from 1 and increment i by 2 till we reach 99
*/
PrintOdd()
Begin
for (i = 1; i <= 100; i = i + 2)
Print: i and go to new line;
endfor
End
```

Note! In this case we have used C style for loop

```
/*
Variable n will store user input while sum will store the result.
We start from i=1 and move up to n and add the number as follows
sum = sum + i
*/
SumToN()
Begin
Read: n;
Set sum = 0;
for i = 1 to n by 1 do
Set sum = sum + i;
endfor
Print: sum;
End
```

```
/*
Let a[0:n-1] be a 1D array of n elements.
We’ll use big to store the biggest element of the array.
We start with big=a[0];
Array is of n elements so starting index = 0 and ending index = n-1
*/
FindBig()
Begin
Set big = a[0];
for i = 1 to n-1 by 1 do
if a[i]>big then
Set big = a[i];
endif
endfor
Print: big;
End
```

```
/*
Algorithm starts from the Main module.
Variable n stores the user input.
*/
Main()
Begin
Read: n;
for i = 1 to n by 1 do
if i%2==0 then
Call Square(i);
else
Call Cube(i);
endif
endfor
End
/*
Square module will store value passed by Main module in x and print the square
*/
Square(x)
Begin
Print: x*x and go to new line;
End
/*
Cube module will store value passed by Main module in x and print the cube
*/
Cube(x)
Begin
Print: x*x*x and go to new line;
End
```

Factorial of n is represented as n! where

n! = 1*2*3*…*(n-2)*(n-1)*n

Example

3! = 1*2*3 = 6

```
/*
Algorithm starts here.
Variable n stores the user input while x stores the result.
*/
Main()
Begin
Read: n;
Set x = Call Fact(n);
Print: x;
End
/*
Fact module will store value passed by Main module in num and
will return the factorial of num back to Main
*/
Fact(num)
Begin
Set f = 1;
for i = 2 to num by 1 do
Set f = f * i;
endfor
return f;
End
```

```
/*
Variable p, r and t will store the principal,
rate and time respectively while si will store the result.
We are using the formula
si=(p*r*t)/100
*/
SimpleInterest()
Begin
Read: p, r, t;
Set si=(p*r*t)/100;
Print: “Simple Interest = ”, si;
End
```

- Docker - Commands Docker
- Docker - How to build docker image and publish to DockerHub Docker
- Docker - Getting Started Docker
- Docker - run command Docker
- PostgreSQL - LEFT JOIN PostgreSQL
- PostgreSQL - INNER JOIN PostgreSQL
- PostgreSQL - ORDER BY and LIMIT PostgreSQL
- PostgreSQL - Alias PostgreSQL
- PostgreSQL - DELETE FROM Table PostgreSQL
- PostgreSQL - UPDATE Table PostgreSQL