Assignment 3
Chapter 2: Algorithm Discovery and Design
More about Pseudocode
ALGORITHM 1 (PRIME NUMBER)
check_prime()
{
read N
flag=1
for i =2 to n/2 , do
{
if N%i=0, then
{
flag=0
break
}
}
if N=1,then flag=0
if flag=1, then print "prime"
else
{
print "not prime"
print "The factors of N are:"
for i=1 to N, do
{
if N%i==0, then print "i"
}
}
}
ALGORITHM 2 (TOTAL COST)
total_cost()
{
read Price
read Quantity
cost=Price*Quantity*1.06
print "cost"
}
ALGORITHM 3 (DIVISION)
division()
{
read x
read y
if y=0, then
{
print "Unable to perform the division."
}
else
{
result= x/y
print "result"
}
}
ALGORITHM 4(CIRCLE)
circle()
{
read R
Circum = 2* 3.14 * R
if R>=1.0, then
{
Area= 3.14 * R * R
print "Area"
print "Circum"
}
else
{
print "Circum"
}
}
Hope my answer is relevant to the question you asked and is easy to understand. Feel free to ask any doubts in the comments section.
Get Answers For Free
Most questions answered within 1 hours.