100% found this document useful (2 votes)
10K views

Examples of Algorithms: Write An Algorithm To Add Two Numbers Entered by User

The document provides examples of algorithms to perform various calculations and checks: 1) An algorithm to add two numbers by declaring variables, reading input, performing addition, and displaying the sum. 2) An algorithm to find the largest of three numbers by declaring variables, reading input, comparing numbers, and displaying the largest. 3) An algorithm to calculate the Fibonacci series up to a term less than or equal to 1000 by initializing variables, displaying terms, and calculating the next term in the series through addition and variable updates.

Uploaded by

bhatt navtej
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
10K views

Examples of Algorithms: Write An Algorithm To Add Two Numbers Entered by User

The document provides examples of algorithms to perform various calculations and checks: 1) An algorithm to add two numbers by declaring variables, reading input, performing addition, and displaying the sum. 2) An algorithm to find the largest of three numbers by declaring variables, reading input, comparing numbers, and displaying the largest. 3) An algorithm to calculate the Fibonacci series up to a term less than or equal to 1000 by initializing variables, displaying terms, and calculating the next term in the series through addition and variable updates.

Uploaded by

bhatt navtej
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Examples of Algorithms

Write an algorithm to add two numbers entered by user.

Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop

Write an algorithm to find the largest among three different numbers entered by user.
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a>b
If a>c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b>c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop

Write an algorithm to find the Fibonacci series till term≤1000.

Step 1: Start
Step 2: Declare variables first_term,second_term and temp.
Step 3: Initialize variables first_term←0 second_term←1
Step 4: Display first_term and second_term
Step 5: Repeat the steps until second_term≤1000
5.1: temp←second_term
5.2: second_term←second_term+first term
5.3: first_term←temp
5.4: Display second_term
Step 6: Stop
Write an algorithm to find the factorial of a number entered by user.

Step 1: Start
Step 2: Declare variables n,factorial and i.
Step 3: Initialize variables
factorial←1
i←1
Step 4: Read value of n
Step 5: Repeat the steps until i=n
5.1: factorial←factorial*i
5.2: i←i+1
Step 6: Display factorial
Step 7: Stop

Write an algorithm to check whether a number entered by user is prime or not.

Step 1: Start
Step 2: Declare variables n,i,flag.
Step 3: Initialize variables
flag←1
i←2
Step 4: Read n from user.
Step 5: Repeat the steps until i<(n/2)
5.1 If remainder of n÷i equals 0
flag←0
Go to step 6
5.2 i←i+1
Step 6: If flag=0
Display n is not prime
else
Display n is prime
Step 7: Stop

You might also like