1.4 Algorithm: An algorithm is a method of representing step by step logical procedure for solving a particular task
1. Write an algorithm to add two numbers
Step1: start
Step2: declare a, b
Step2: read a, b values
Step3: display a+b
Step4: stop
2. Write an algorithm to find average of six subjects
Step1: start
Step2: declare tel, hin, eng, mat, sc, cs, tot, avg
Step3: read subject marks tel, hin, eng, mat, sc, cs
Step4: tot = tel+hin+eng+mat+sc+cs
Step5: avg = tot / 6
Step6: display avg
Step7: stop
3.Write an algorithm to find the largest between two different numbers entered by user.
Step 1: Start
Step 2: Declare variables a,b
Step 3: Read variables a,b
Step 4: If a>b
Display a is the largest number.
Else
Display b is the largest number.
.Step 5: Stop
4.Write an algorithm to print n natural numbers
Step 1: Start
Step 2: Declare variables i , num
Step 3: i=1
Step 4: Read the value for num
Step 5: if(i<num) then
Display i value
i = i+1
Step 6: if(i<num) go to Step 5 else goto step 7
Step 7: Stop
No comments:
Post a Comment