World's most popular travel blog for travel bloggers.

Write an algorithm, draw a flow chart and write its corresponding C program to convert a decimal number to its equivalent hexadecimal number.

, , No Comments
An algorithm is a finite set of steps defining the solution of a particular problem. An algorithm is expressed in pseudo code – something resembling C language or Pascal, but with some statements in English rather than within the programming language
  1. A sequential solution of any program that written in human language, called algorithm.
  2. Algorithm is first step of the solution process, after the analysis of problem, programmers write the algorithm of that problem.
Pseudo code 
  • Input Num
  • Initialize Len to zero and Y to Num
  • While Y is not zero
  •                Save Remainder by Y Mod 16 in array HEXD at index Len
  •                Initialize Y to Y divided 16
  •                Increment Len
  • for(Initialize I to Len-1 ; Condition I Greater than  -1 ;  Decrement I )
  •                If HEXD[I] Less than 10
  •                           HEXC[I]=HEXD[I]+48
  •                Else
  •                           HEXC[I]=HEXD[I]+55
  • Initialize HEXC[I] to NULL
  • Print HEXC
Detailed Algorithm:
Step 1:  Input NUM
Step 2:  LEN = 0 & Y=NUM
Step 3:  While (Y > 0)
                       HEXD[LEN]=Y%16
                       Y=Y/16
                       LEN++
Step 4: for(I=LEN-1;I>-1;I–)
                       IF(HEXD[I]<10)
                                HEXC[I]=HEXD[I]+48;
                       ELSE
                                HEXC[I]=HEXD[I]+55;
Step 5:  HEXC[I]=NULL
Step 5:  Print HEXC

Flowchart:-


0 comments:

Post a Comment

Let us know your responses and feedback