0% found this document useful (0 votes)
7 views

Algorithms 7-13

The document contains algorithms and flowcharts for various mathematical operations and calculations like addition, subtraction, multiplication, division, interchanging numbers, finding the largest number, checking even and odd numbers, printing natural numbers, and calculating the area and perimeter of shapes like triangle, rectangle, square and circle.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Algorithms 7-13

The document contains algorithms and flowcharts for various mathematical operations and calculations like addition, subtraction, multiplication, division, interchanging numbers, finding the largest number, checking even and odd numbers, printing natural numbers, and calculating the area and perimeter of shapes like triangle, rectangle, square and circle.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

7.

Write an algorithm to add, subtract, multiply and divide for given 2 variables and draw a
flowchart for the same.
Ans:
1. Start
2. Input the two integers ‘num1’ and ‘num2’
3. SUM=num1+num2
4. Print ‘SUM’
5. DIFF=num1-num2
6. Print ‘DIFF’
7. PROD=num1*num2
8. Print ‘PROD’
9. If (num1==0 or num2==0): “Error”; Jump: Step 11
Else: QUOT= num1/num2
10. Print ‘QUOT’
11. End
8. Write an algorithm to interchange two numbers and draw a flowchart for the same.
Ans:
1. Start
2. Input the two integers ‘num1’ and ‘num2’
3. Declare a third variable ‘temp’
4. Assign the value of ‘num1’ to ‘temp’
5. Assign the value of ‘num2’ to ‘num1’
6. Assign the value of ‘temp’ to ‘num2’
7. Print ‘num1’ and ‘num2’ with interchanged values
8. End
9. Write an algorithm to test the equality of two numbers and draw a flowchart for the
same.
Ans:
1. Start
2. Input two integers ‘num1’ and ‘num2’
3. If (num1>num2) : Print ‘num1’ greater than ‘num2’
If else (num2>num1): Print ‘num2’ is greater than ‘num1’
Else: Print ‘num1’ is equal to ‘num2’
4. End
10. Write an algorithm to find largest of the 2 numbers and draw a flowchart for the same.
Ans:
1. Start
2. Input two integers ‘num1’ and ‘num2’
3. If (num1>num2) : Print ‘num1’ greater than ‘num2’
If else (num2>num1): Print ‘num2’ is greater than ‘num1’
Else: Print ‘num1’ is equal to ‘num2’
4. End
11. Write an algorithm to check whether a number is odd or even and draw a flowchart for
the same.
Ans:
1. Start
2. Input an integer as ‘num’
3. If (num/2)=0 : Print ‘num’ is even
Else: Print ‘num’ is odd
4. End
12. Write an algorithm to print 10 natural numbers.
Ans:
1. Start
2. Declare a variable ‘k’ as 1
3. Print ‘k’
4. Increment the value of ‘k’ by 1
5. Repeat Step 3 and Step 4 until value of ‘k’ is 11
6. End
13. Write an algorithm to find the area and perimeter of a triangle, area of a rectangle,
square and circle and flowchart for the same.
Ans:
Algorithm for Area and Perimeter of Triangle
1. Start
2. Input the length of the sides of the triangle as ‘s1’ ‘s2’ and ‘s3’
3. PM=s1+s2+s3
4. SEMIPM=PM/2
5. AREA=sqrt(SEMIPM*(SEMIPM-s1)*(SEMIPM-s2)*(SEMIPM-s3))
6. Print ‘PM’ as the perimeter of the triangle
7. Print ‘AREA’ as the area of the triangle
8. End

Algorithm for Area and Perimeter of Rectangle

1. Start
2. Input the length and breadth of the rectangle as ‘L’ and ‘B’
3. PM= 2*(L+B)
4. AREA=L*B
5. Print ‘PM’ as the perimeter of the rectangle
6. Print ‘AREA’ as the area of the rectangle
7. End

Algorithm for Area and Perimeter of Square

1. Start
2. Input the side of the square as ‘side’
3. PM= 4*side
4. AREA=side*side
5. Print ‘PM’ as the perimeter of the square
6. Print ‘AREA’ as the area of the square
7. End

Algorithm for Area and Perimeter of Circle

1. Start
2. Input the radius of the circle as ‘radii’
3. Declare a variable ‘pi’ and set ‘pi=3.14’
4. PM=2*pi*radii
5. AREA=pi*radii*radii
6. Print ‘PM’ as the perimeter of the circle
7. Print ‘AREA’ as the area of the circle
8. End

You might also like