Important Algorithm For CPRG Theory Exam

Most important Algorithms for IPLC theory exam :

1. Write an algorithm to input a number and display factorial of that number.
ANS)

//Algorithm to calculate the factorial of a number
step 1. Start
step 2. Read the number n
step 3. declare
             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


2. Write an algorithm to Generate Fibonacci series.
ANS)

Step 1: Start
Step 2: Declare variables n, n1, n2, n3, i.
Step 3: Accept value of N from user.
Step 4: if N < 2, display message “Enter num greter than 2” and go to step 9.
Step 5: Initialize variables n1 = 0, n2 = 1, i = 0
Step 6: Display n1, n2  
Step 7: Compute n3 = n1 + n2
Step 8: Repeat following statements until i < N
        Display N3
        N1 = N2
        N2 = N3  
        N3 = N1 + N2
        i  = i + 1
Step 9: Stop

3. Write and Algorithm to Find the Largest Number Among Three Numbers : 
ANS)

Step-1. Start
Step-2. Read the three numbers to be compared, as n1, n2 and n3.
Step-3. Check if n1 is greater than n2.
Step- 3.1 If true, then check if n1 is greater than n3.
    If true, 
print 'n1' as the greatest number.
    If false,
print 'n3' as the greatest number.
Step- 3.2 If false, then check if n2 is greater than n3.
      If true, 
print 'n2' as the greatest number.
    If false,
print 'n3' as the greatest number.
Step-4. Stop

4. Write and Algorithm to Find the Smallest Number Among Three Numbers :
ANS)

Step-1. Start
Step-2. Read the three number  n1, n2 and n3.
Step-3. Check if n1 is less than n2.
If true,
min=n1
  If false,
min=n2
Step- 4 check if n3 is less than min.
      If true, 
min=n3
step-4  Print Min

Step-5  Stop

5. Write an Algorithm to check the number is armstrong or not....
ANS)

Step-1. Start
Step-2. read number from user
Step-3. set sum=0 and temp=number
Step-4. reminder=number%10
Step-5. sum=sum+(reminder*reminder*reminder)
Step-6. number=number/10
Step-7. repeat steps 4 to 6 until number > 0
Step-8. if sum = duplicate
                 display number is armstrong
           else
                 display number is not armstrong
Step-9. stop

6. Write an algorithm to Interchange two variables's value.(Swapping).
ANS)

Step-1. Start
Step-2. Read the three number  n1 and n2.
Step-3. 
  temp=n1
n1=n2
n2=temp
Step-4. print n1,n2.
Step-5. Stop.


7. Write an algorithm to inout two numbers and display largest number.
ANS)

Step-1. Start
Step-2. Read the three number  n1 and n2.
Step-3. Check if n1 is greater than n2.
If true,
print n1 as largest.
  If false,
print n2 as largest.

Step-4 Stop

8. Write an algorithm to inout two numbers and display smallest number.
ANS)


Step-1. Start
Step-2. Read the three number  n1 and n2.
Step-3. Check if n1 is less than n2.
If true,
print n1 as smallest.
  If false,

print n2 as smallest.
Step-4 Stop

Comments

Popular posts from this blog

C++ Practice Program

Cloud Computing Important Question-Answer for University Exam

Software Testing Gujarat University Important Questions For Exam