Thursday, April 2, 2015

what is algorithms in computer programming - "Algorithms"


"Algorithms"

what is algorithms in computer programming - "Algorithms"


what is algorithms in computer programming


• A well-defined set of steps to provide a solution of a 
   specific problem.



Characteristics:


An algorithm should have zero or more 

input.

An algorithm should exhibit at least one 

output.

An algorithm should be finite.

Each instruction in an algorithm should be

 defined clearly. 

Each instruction used in an algorithm

 should be basic and easy to perform.




Why Algorithms are Useful?



• Once we find an algorithm for 

solving a problem, we do not need to 

re-discover it the next time we are 

faced with that problem.


Once an algorithm is known, the task 

of solving the problem reduces to 

following (almost blindly and without 

thinking) the instructions precisely


 All the knowledge required for solving

 the problem is present in the 

algorithm




Representing an algorithm



Pseudo-code convention


Flowcharts



Guideline for developing algorithm



• Each algorithm will be logically enclosed by two 

    statements START and STOP.


•  To accept the data from user, the INPUT or READ 

    statements are to be used.


•  To display any user message or the content in a variable, 

   PRINT statement will be used.

• Message will be enclosed within quotes.




The arithmetic operators that will be used in expressions are



o‘=‘ Assignment

o‘+’ Addition

o‘*’ Multiplication

o‘-’ Subtraction

o‘/’ Division


• Commonly used relational operators are



o‘<‘, ‘>’, ‘<=‘, ‘>=‘, ‘=‘, ‘!=‘



• Most commonly used logical  operators will be



o‘AND’ Conjunction


o‘OR’ Disjunction


o‘NOT’ Negation

 



Write Algorithm to find sum of any two numbers




•  START

•      PRINT “ENTER TWO NUMBERS”

•      INPUT A, B

•      C = A + B

•      PRINT C

•  STOP





Write an Algorithm to check weather a number given by the user is odd or even.




•    START


•        PRINT “ENTER THE NUMBER”


•        INPUT N


•        Q = N / 2


•        R = N – Q * 2


•        IF R = 0 THEN


o   PRINT “ N IS EVEN”


•        IF R != 0 THEN


o   PRINT “ N IS ODD”


•   STOP




Write an Algorithm to find largest no from three numbers.



START

PRINT “ENTER THREE NUMBERS”

READ A, B, C

IF A>B AND A>C THEN

oPRINT A

IF B>C AND B>A THEN

oPRINT B

       ELSE 

               PRINT C


STOP




Write an Algorithm to find largest no from three numbers.




START

PRINT “ENTER THREE NUMBERS”

READ A, B, C

MAX = A

IF B > MAX

oMAX =B

      ELSE IF C > MAX 

           MAX = C

      END IF

PRINT MAX

STOP



Write a Algorithm FOR FINDING THE SUM OF THE 

SERIES 

1+2+3+4+…… UP TO N



1.START

2.PRINT “ENTER THE NUMBER”

3.READ N

4.SUM = 0

5.COUNT = 0

6.COUNT = COUNT + 1

7.SUM = SUM + COUNT

8.IF COUNT < N

1.THEN GOTO STEP 6

9.PRINT SUM

10.STOP


Write a Algorithm TO DISPLAY THE SERIES

2 10 30 68 130 ……..UP TO GIVEN TERM

2 10 30 68 130 ……..UP TO GIVEN TERM





1.START

2.PRINT “ENTER THE NUMBER”

3.READ N

4.COUNT = 0

5.COUNT = COUNT + 1

6.VAL = COUNT * COUNT * COUNT + COUNT

7.PRINT VAL

8.IF COUNT < N THEN GO TO STEP 5

9.STOP


Write a AlgorithmTO FIND THE SUM OF THE SERIES 


1+x+x2+x3+x4+….. Up to n TERMS


1.START

2.PRINT “HOW MANY TERMS “

3.INPUT N

4.PRINT “ENTER THE VALUE OF X”

5.INPUT X

6.TMP=1

7.COUNT=1

8.SUM=0

9.SUM = SUM + TMP

10.COUNT = COUNT + 1

11.TMP = TMP * X

12.IF COUNT <= N THEN GOTO STEP 9

13.PRINT SUM

14.STOP



Write an algorithm to find weather a given no is 


prime or not



1.START

2.PRINT “ENTER THE NUMBER”

3.INPUT N

4.IF N = 2 THEN

1.PRINT “CO- PRIME” GO TO STEP 11

5.D = 2

6.R = N % D

7.IF R = 0 THEN GO TO STEP 10

8.D = D + 1

9.IF D <= N/2 THEN GO TO STEP 6

10.IF R = 0 THEN

 PRINT “NOT PRIME”

 ELSE

 PRINT “PRIME”

11.STOP




Write an algorithm to find factorial of number n.



START

PRINT “ENTER THE NUMBER”

INPUT N

F=1

C=1

WHILE C <= N

BEGIN

F = F * C
o C = C + 1

END

PRINT F

STOP



Write a Algorithm for computing sum of digit in a number



1.START

2.PRINT “ENTER THE NUMBER”

3.INPUT N

4.SUM = 0

5.REM = N % 10

6.N = N / 10

7.SUM = SUM + REM

8.IF N > 0 THEN GOTO STEP 5

9.PRINT SUM

10.STOP


Write a Algorithm to find given number is palindrom or not




1.START

2.PRINT “ENTER NUMBER”

3.INPUT N

4.TMP = N

5.REV = 0

6.REM = TMP % 10

7.REV = (REV * 10) + REM

8.TMP = TMP / 10

9.IF TMP > 0 THEN GOTO STEP 6

10.IF REV = N THEN

1.PRINT “PALINDROM NUMBER”

11.ELSE

1.PRINT “NOT PALINDROM”

12.STOP




Write a Algorithm TO CHECK 

WHEATHER A GIVEN NUMBER IS AN 

ARMSTRONG NUMBER OR NOT.




1.START

2.PRINT “ENTER THE NUMBER”

3.INPUT N

4.TMP = N

5.SUM = 0

6.REM = TMP % 10

7.TMP = TMP / 10

8.SUM = SUM + REM * REM * REM

9.IF TMP > 0 THEN GOTO STEP 6

10.IF N = SUM THEN

1.PRINT “ ARMSTRONG NUMBER”

 ELSE

1.PRINT “NOT ARMSTRONG NUMBER”

11.STOP


what is algorithms in computer programming


0 comments:

Post a Comment