Technical Point.

The Best Platform of Diploma CSE Students.

Subscribe Us

Breaking

Wednesday, July 29, 2020

ALGORITHM FOR PROBLEM SOLVING Unit 02



ALGORITHM FOR PROBLEM SOLVING   Unit 02
·      Exchanging values of two variables
Algorithm :-

Step 1            Start
Step 2            Take input A,B
Step 3            Temp=A
Step 4            A=B
Step 5            B=Temp
Step 6            Print A,B
Step 7            Stop  

·       Algorithm for prime Number
Algorithm:-
         
Step1             Start
Step 2            Input a positive integer n
Step 3            set F=0, i=2;
Step 4            Repeat step 5 until i<=n-1
Step 5            if (n%i==0) then set F=1 and go to step 6 else i=i+1
Step 6            if (F==1) print n is not a prime number else Print n is prime Number
Step 7            Stop

·      Algorithm to find out GCD/HCF of two number
Algorithm :-

Step 1            Start
Step 2            input two number A and B
Step 3            if (A==0) then print GCD=B and Exit
Step 4            if (B==0) then print GCD=A and Exit
Step 5            if (A==B) then print GCD=A and exit
Step 6            Repeat step 7 while (A≠B)
Step 7            if (A>B) then A=A-B , else B=B-A
Step 8            Print GCD = A
Step 9            Stop

·      Algorithm to find Factorial of a given numbers
Algorithm:-

Step 1            Start
Step 2            Read  +ve integer number n
Step 3            set i=1 , fact=1
Step 4            Repeat step 5, while (i<=n)
Step 5            fact=fact*I , i=i+1
Step 6            Print fact
Step 7            Stop

·      Write an Algorithm to find sum of first n natural number and find out there mean value.
Algorithm:-

Step 1                      Start
Step 2                      Read natural number n
Step 3                      Set sum=0 , Num=1
Step 4                      Repeat step 5 while (num<=n)
Step 5                      sum=sum+num
   num=num+1
Step 6                      Mean= sum/n
Step 7                      print sum of n natural number s=sum
Step 8                      Print mean of n natural
                                w.s=mean
  Step 9                      Stop  


·       Write an algorithm to arrange three integer in ascending order
Algorithm:-
Step 1            Start
Step 2            Read three Number a , b, c
Step 3            if a
Step 4            if a
Step 5            if b
Step 6            inter change b and c  and go to step 9
Step 7            inter change a and c and go to step 5
Step 8            inter change a and b and go to step 4
Step 9            print “Ascending Number”
Step 10          print a, b,  c
Step 11          Stop

·       Write an algorithm to find out sum of digit of a given number
Algorithm:-

Step 1                  Start
Step 2                  Read natural number n
Step 3                  set sum=0
Step 4                  Repeat step 5, while (n≠0)
Step 5                  rem=n%10
  sum=sum+rem
  n=n/10
Step 7                  print sum
Step 8                  Stop

·       Write an algorithm for reversing digit of an integer
Algorithm
Step 1                  Start
Step 2                  Read  a natural no n
Step 3                  set reverse=0
Step 4                  Repeat step 5 while (n≠0)
Step 5                  rem=n%10
  Reverse = reverse*10+rem
  n=n/10
Step 6                  Print reverse
Step 7                  Stop


·       Check whether a given number is Palindrome or not
Algorithm
Step 1                  Start
Step 2                  Read  a natural no n
Step 3                  set reverse=c , n=num
Step 4                  Repeat step 5 while n>0
Step 5                  rem=n%10
  Reverse = reverse*10+rem
  num=num/10
Step 6                  Print reverse
Step 7                  if (n==reverse) print n is palindrome .
  else print n is not palindrome No.
Step 8                 Stop

·       Algorithm for Fibonacci sequence
Algorithm:-
Step 1            Start
Step 2            set A=0 , B=1 , counter =0
Step 3            input n
Step 4            write A
Step 5            Write B
Step 6            Repeat step 7 to 11 while (counter<=n-2)
Step 7            set sum=A+B
Step 8            Print Sum
Step 9            Set A=B
Step 10          set B=sum
Step 11          set counter=counter+1
Step 12          Stop
·       Algorithm to Find  out Square root of a given number
Algorithm:-
Step 1            Start
Step 2            Read  natural number n
Step 3            if [x==0|| x==1] print x and exit
Step 4            set i=1 , result=1
Step 5            Repeat step 6 while (result<=x)
Step 6            i=i+1  , result =i*i
Step 7            print=i-1
Step 8            Stop

·       Algorithm to Find Square root of a quadratic equation
Algorithm:-
Step 1                  Start
Step 2                  input a, b, c
Step 3                  set d=b*b-4*a*c
Step 4                  if (a==0) print invalid and exit
Step 5                  if (d>0) then print roots are real and different
  Set x1 =  -b+ √d / 2*a
  Set x2 = -b- √d / 2*a
  Print x1, x2
Step 6                 else if (d==0) then print roots are real and equal
 Set , x1 = -b /2*a
 Set , x2 = -b/2*a
 Print x1 and x2
Step 7                else print roots are complex
Step 8                Stop



No comments:

Post a Comment

Recently

All C program

Write a C program to print ‘Hello World’ on screen . #include < stdio.h > #include < conio.h > void  m...