You are on page 1of 14

GE3151 – PSPP (BRIDGE COURSE 2)

CHARACTERISTICS
Hello world
Step 1: Start
Step 2: Print the word
Step 3: Stop
Program
print("hello world")

OUTPUT
hello world
Addition of two numbers
Algorithm
Step 1: Start
Step 2: Initialize the variable a, b
Step 3: Sum the values
Step 4: Print Sum
Step 5: Stop
PROGRAM
a=5
b=5
Sum=a+b
print Sum
OUTPUT
10
Swapping( Without temp variable)

Algorithm
Step 1: Start
Step 2: Initialize the variable x, y
Step 3: Print the values before swapping
Step 4: Swap the values
Step 5: Print the values after swapping
Step 6: Stop
Program
x=5
y=7
print ("Before swapping: ")
print("Value of x : ", x, " and y : ", y)
# code to swap 'x' and 'y'
x, y = y, x
print ("After swapping: ")
print("Value of x : ", x, " and y : ", y)

OUTPUT:
Before swapping:
Value of x : 5 and y : 7
After swapping:
Value of x : 7 and y : 5
Swapping( Without temp variable)
Algorithm
Step 1: Start
Step 2: Initialize the variable x, y
Step 3: Print the values before swapping
Step 4: Perform x = x + y
y=x–y
x=x-y
Step 5: Print the values after swapping
Step 6: Stop
Program
x = 5.4
y = 10.3
print (“Before swapping: ")
print("Value of x : ", x, " and y : ", y)
# Swap code
x = x + y # x = 15.7, y = 10.3
y = x - y # x = 15.7, y = 5.4
x = x - y # x = 10.3, y = 5.4
print ("After swapping: ")
print("Value of x : ", x, " and y : ", y)
OUTPUT
Before swapping:
Value of x : 5.4 and y : 10.3
After swapping:
Value of x : 10.3 and y : 5.4
Swapping(With temp variable)

Algorithm
Step 1: Start
Step 2: Initialize the variable x, y
Step 3: Print the values before swapping
Step 4: Perform temp =x
x=y
y = temp
Step 5: Print the values after swapping
Step 6: Stop
PROGRAM
x=5
y = 10
# To take inputs from the user
#x = input('Enter value of x: ')
#y = input('Enter value of y: ')
# create a temporary variable and swap the values
temp = x
x=y
y = temp
print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))

OUTPUT:
The value of x after swapping: 10
The value of y after swapping: 5
Area of triangle

Algorithm
Step 1: Start
Step 2: Initialize the variable a,b & c
Step 3: Perform s=(a+b+c)/2
(formula for semi perimeter)
Step 4: Perform area =(s*(s-a)*(s-b)*(s-c)) **
0.5
Step 5: Print the value of area(area of triangle)
Step 6: Stop
Program
a = float(input('Enter first side: '))
b = float(input('Enter second side: '))
c = float(input('Enter third side: '))
# calculate the semi-perimeter
s = (a + b + c) / 2
# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)

OUTPUT
Enter first side: 1.2
Enter second side: 2.3
Enter third side: 3.4
The area of the triangle is 0.67

You might also like