Cproblemset 2

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 10

Computer Programming Lab 2017-18

CYCLE-1
1.1: Write an algorithm and Flowchart for converting Celsius to Fahrenheit

Algorithm:
Step 1 : Begin
Step 2 : Read Celsius value
Step 3 : compute f = ( Celsius * 9/5) + 32
Step 4 : Print f Value
Step 5 : End

Flow Chart:

start

Read Celsius value

F=(Celsius * 9/5)+32

Print f value

Stop
Sreenidhi Institute of Science and Technology Page
1
Computer Programming Lab 2017-18

1.2: Write an algorithm to find the greatest among three numbers and draw
the flowchart
Algorithm :

Step 1 : Begin
Step 2 : Read a,b,c values
Step 3 : if ( (a > b) and (a>c)) then
step 3.1 : Print “ a is Big”
Step 4 : else if (b > c ) then
Step 4.1 : Print “ b is
Big” Step 5 : else
Step 5.1 : Print “ c is
Big” Step 6 : End
Flowchart:
Sreenidhi Institute of Science and Technology Page
2
Computer Programming Lab 2017-18

1.3: Write an algorithm and Flowchart for finding roots and nature roots of
Quadratic equation, given its coefficients

Algorithm :
Step 1 : Begin
Step 2 : Read a, b,c values
2
Step 3 : Calculate d = b - 4ac
Step 4 : if ( d = 0) then
4.1 : Print “ The Roots are Real and Equal”
4.2 : calculate r1 = - b / 2a
4.3 : calculate r2 = - b / 2a
4.4 : Print r1,r2 values go to step 7.
Step 5 : else if( d > 0) then
5.1 : Print “ The Roots are Real and Un Equal”
5.2 : calculate r1 = (- b + sqrt(d)) / 2a
5.3 : calculate r2 = (- b - sqrt(d)) / 2a
5.4 : Print r1,r2 values go to step 7.
Step 6 : else
6.1 : Print “ The Roots are Imaginary”
6.2 : calculate rp = - b / 2a
6.3 : calculate ip = sqrt(- d)/2a
6.4 : Print r1 = rp ‘+ i’ ip value
6.5 : Print r2 = rp ‘- i’ ip value
Step 7 : End
Sreenidhi Institute of Science and Technology Page
3
Computer Programming Lab 2017-18

Flowchart:
Sreenidhi Institute of Science and Technology Page
4
Computer Programming Lab 2017-18

1.4: Write an algorithm and flowchart to finding the first n Fibonacci


Numbers given n

Algorithm:
Step 1 : Begin
Step 2 : Read n value
Step 3 : initialize f1=0,f2=1,i=3
Step 4 : Print f1,f2 values
Step 5: if ( i<=n) then go to step 5.1 else go to step 6
Step 5.1 : compute f3 = f1 + f2
Step 5.2 : print f3 value
Step 5.3 : initialize f1 = f2 and f2 = f3
Step 5.4 : I = I + 1 go to step 5
Step 6 : end

Flowchart:
Sreenidhi Institute of Science and Technology Page
5

You might also like