No title

Algorithm Solved Questions

1. Approach(Sequential)

# Write an algorithm to display your name and address.
Name : name
Address: add  
 
Step 1: Start
Step 2: Declare the variables name, address.
Step 3: Read values of name, address from the user.
Step 4: Display name, address.
Step 5: End.
 
# Write an algorithm to add two numbers.
First Number : num1
Second Number : num2
Result : ans
 
Step 1: Start
Step 2: Read num1,num2
Step 3: ans = num1+num2
Step 4: Print ans
Step 5: Stop
 
# Write an algorithm to calculate simple interest.
Amount: amount
Rate: rate
Time: time
Simple Interest: SI
Formula: SI= ((amount*rate*time)/100)
 
Step 1:Start.
Step 2:Read Principal Amount, Rate and Time.
Step 3:Calculate Interest using formula
Step 4:Print Simple Interest.
Step 5:Stop.
 
2. Approach (Selection)

# Write an algorithm which accepts the length of two different line segments and check whether they are equal or unequal. Display the message accordingly.
Line One: l1
Line Two: l2
 
Step 1: Start
Step 2: Accept the length of the two line segments as l1 and l2.
Step 3: If l1 and l2 are equal, then display 'Line Segments are equal'.
Step 4: If l1 and l2 are not equal, then display 'Line Segments are not equal'.
Step 5: Stop
 
# Accept the age of a person and check whether he/she is eligible to vote or not. A person is eligible to vote only when he/she is 18 years or more.
 
Step 1: Start
Step 2: Accept the age of the person.
Step 3: If age is greater than or equal to 18, then display 'You are eligible to vote'.
Step 4: If age is less than 18, then display 'You are not eligible to vote'.
Step 5: Stop
 
# Write an algorithm which accepts three numbers and check whether they are 'Pythagorean Triplets' or not. Display the message accordingly.
(Hint: Use Pythagoras Formula for a Right-angled Triangle: h = p2+b2)

Step 1: Start
Step 2: Get three numbers a , b , c
Step 3: if ( (a*a + b*b) == c*c ) then
Step 4: Display "These numbers are Pythagorean triplets. "
Step 5: else
Step 6: Display "Numbers are not Pythagorean triplets. "
Step 7: end if
Step 8:Stop
 
3. Approach (Iterative/ Looping)
 
# Write an algorithm using iterative approach to print numbers from 1 to 10.

Step 1: Start Initialize variable K to 1, K=1

Step 2: Output K 

Step 3: Increment K by 1

K=K+1

Step 4: Check if the value of K is less than or equal to 10. IF K<=10 THEN GO TO step 2 otherwise GO TO Step 5

Step 5: Stop

# Write an algorithm using iterative approach to find the factorial of a number.
Step 1. Start 
Step 2. Read the number n 
Step 3. i=1, fact=1 
Step 4. Repeat Step 4 through 6 until i=n 
Step 5. fact=fact*i 
Step 6. i=i+1 
Step 7. Print fact 
Step 8. Stop   

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.