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

Algorithms and Flowcharts

The document provides algorithms and flowcharts for determining if a number is prime, finding the minimum and maximum of a data set, and solving a quadratic equation. The prime number algorithm checks if a given number is evenly divisible by numbers from 1 to itself. The minimum/maximum algorithm reads numbers from the user, tracks the lowest and highest, and reports them. The quadratic formula algorithm calculates and outputs the roots based on the discriminant.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views

Algorithms and Flowcharts

The document provides algorithms and flowcharts for determining if a number is prime, finding the minimum and maximum of a data set, and solving a quadratic equation. The prime number algorithm checks if a given number is evenly divisible by numbers from 1 to itself. The minimum/maximum algorithm reads numbers from the user, tracks the lowest and highest, and reports them. The quadratic formula algorithm calculates and outputs the roots based on the discriminant.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Write an Algorithms for finding if a number is prime number or Not.

Step 1: Start
Step 2: Read the value of 'N' from the user to check if it is a prime number.
Step 3: Declare and set count to 0 and i to 1.
Step 4: If i is less than or equal to N, (i<=N) go to Step 5; otherwise, go to Step 8.
Step 5: Check the condition N % i == 0. If true, go to Step 6; otherwise, go to Step 7.
Step 6: Increment count by 1(count=count+1).
Step 7: Increment i by 1(i=i+1) and go to Step 4.
Step 8: Check count. If count is equal to 2, (count==2) go to Step 9; otherwise, go to Step 10.
Step 9: Display "N is a prime number."
Step 10: Display "N is not a prime number."
Step 11: Stop.
Write an Algorithms for finding minimum and maximum numbers of a given set.
Step 1: Start
Step 2: Declare integer variables n, num, min, max, and i.
Step 3: Read the value of n from the user.
Step 4: Enter a loop from i = 1 to n (i=1; i<=n).
Step 5: Read an integer num from the user
Step 6: If i is equal to 1, set both min and max to num (min=max=num)
Step 7: If i is greater than 1: - If num is greater than max, update max to num (num>max).
If num is less than min, update min to num.
Step 8: Increment i by 1 to process the next number (i=i+1).
Step 9: After the loop:
a. Display "Maximum number is: max."
b. Display "Minimum number is: min."
Step 10: Stop.

Write an Algorithms for finding roots of a quadratic equation.


Step 1: Start
Step 2: Read coefficients a, b, and c.
Step 3: Compute the discriminant d as d = b^2 - 4ac.
Step 4: If d is greater than 0:(d>0)
Calculate root1 as (-b + sqrt(d)) / (2a)
Calculate root2 as (-b - sqrt(d)) / (2a)
Print root1 and root2.
Step 5: Else if d is equal to 0:(d==0)
Calculate both root1 and root2 as (-b / 2a)
Print root1 and root2.
Step 6: Else (when d is less than 0):(d<0)
Calculate the real part of root1 as (-b / 2a)
Calculate the imaginary part as sqrt(-d) / (2a)
Calculate root1 as real_part + i * imaginary_part
Calculate root2 as real_part - i * imaginary_part
Print root1 and root2.
Step 7: Stop.

Flow charts of
Draw a flowchart for finding if a number is prime number or Not.
Draw a flowchart for finding minimum and maximum numbers of a given set.
Draw a flowchart for finding roots of a quadratic equation.

Draw a flowchart for finding minimum and maximum numbers of a given set.
Start

Declare i=1, min, max,


n, num.

Read ‘n’

Is No
i<=n

Yes

Print min and max


values
Is
No
i==1

Read ‘num’

Yes
Read ‘num’
Stop
Is No

num>max
min=max=num

Yes
num<
min
max=num

Yes

min=num

I=i+1
Draw a flowchart for finding if a number is prime number or Not.

Start

Declare N,count=0,i=1

Read N

Is

i<=N
Yes

Count==2 No
Is

N%i==0
Yes N is not a prime number
Yes

Count=count+1 N is prime number

i=i+1

Stop

You might also like