0 ratings0% found this document useful (0 votes) 79 views9 pagesAlgorithm Exercise
Computer Science with python
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Question 14:
\Wte an algorithm to compute the sum of odd and even numbers up to.
Answer,
The algorithm as
Step 1:Stort
Step 2 Input N.
Step 3 sume «0,
Step 4 sumo =0.
Step 5.ctr=1
(Create POF in your applications withthe Pufcrowd HTML to POF API
‘Step 6 while (tr
(ctr med 2 =o)
‘sume = cume + tr
ee
ume + ett
‘Step 7: Print‘sum of even nurberis* sume.
Step 8 Print ‘sum of odd number is’ surra,
Step 9. EndQuestion 1
©xplain Algorithm
Anewer:
[An algorithm is a step by step instructions required to solve any problem, These instructions are in user's language that means they are
independent of any programming language. 3
Question 2:
write some properties of algorithm.
isis FOF woul apenas Paw S PO AB En
Ansvrer:
‘Some properties of algorithm are
1. An algotithrn should terminate after finite number of steps.
2. An algorithm should be simple so that anyone can understand them property
3. An algorithm should be universal and lead to an unique solution of the problem
4 An algorithm should have capebilty to handle some unexpected situations which may arise during the solution of a particular
problem.
5. An algorithm should be able to soive all problems of a particular type for which it is designed. [Any 3,1 mark for each correct
point]Question 3:
Write some characteristics of algorithm
Answer:
‘Some characteristics of aigorithn are
1. Each and every instruction should be short and clear.
2 Each instruction should be such that it can be performed ina finite time.
3. One oF mare instructions should not be repeated infinitely
4, After performing the instructions the desired result must be cbtained. (Any 3,1 mark for each correct point]
Question 4:
Write an algorithm to calculate sum of two numbers,
Answer:
Create POF in your applications with the Pdfcrowd HTML to POF API
Step 1 Start
Step 2: Read AB.
‘Step 3: Sum=A+B.
Step 4 Print Sum
step 5: Stop‘Question §:
Write an algorithm to calculate simple interest.
Answer:
Step 1: Start
Step 2: Read RRT,
Step 3 :Si=(PARITY/100.
Step 4: Print SI
Step 5: Stop. 8
Question 6:
\Write an algorithm to convert temperature ftom Fahrenhett to Celsius.
Anewer:
Step 1: Start
Step 2: Read F
Step 3: C=(S(F-32))/9.
Step 4: Print C
Step 5: Stop.Question 7:
\rite an algorthm to caleulste area of iangla
Answer:
Step 1 Star.
Step 2:Read abe.
step 2 s=(arbsc}/2
Step 4: Area = ele-al(oa}e-c)
Step 5:Print Area
step 6:Siop.®Question &
Write an algorithen thet generates the fibbonacc! series 2s
11.28, 5.0.N tems,
Answer,
The algorithm as
Step 1 Begin
Step 2: Read N.
step 3: Let a
Step 5: otr= 2,
siepo:c=a+b,
Step 7:a=b.
step 8:b
Step 9° etr= ctr +1
1
Step 4. Printa b.
Create PDF in your applcatons with the Pdicrowd HTL io PDF AP)
Step 10: If cte ¥ continue step 8,
Step 3: If Y>Z thea print’Y is the largest ‘and continue step 7
Step 4 Continue step 6
Step 5: 11> then print ‘Xis the largest “and continue step 7,
Step 6: Prit'Zistaroest’
Step T-En#.”Question 12,
\irte an algorthm to print the bigaer of any two unique given numbers
Answer:
The algorithm as
Step 1 Read two numbers A and 8
Step 2:Compare A and 8
Step 3:if Ais creater than B then, print A else print 8
Step 4: Stop.
Create PDF in your appications with the Pdfcrowd HTML to PDF AP)
Question 13:
\inte an algorthm to inaut N numbers ardifing the largest among them
Answer:
The algoritamas
Step 1 Read N
Step 2: Letotr= 1
Step 3: Read Num.
Step 4 large = Num,
Step 5: Read next Num.
Step 6:08 = ety 47
Step 7: (Num > large) then lage
‘Step 8: if (ctr<=N) then repeat steps 5 and 6
Step 9: Print large
Step 10: End