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.

, , 15 comments

Ans.  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



Program:
#include<stdio.h>
#include<math.h>
#include<conio.h>

int main()
{
      int decimal_number, remainder, hexadecimal_number = 0;
      int count = 0;
      scanf("Enter a Decimal Number:\t");
      scanf("%d", &decimal_number);
      while(decimal_number != 0)
      {
            remainder = decimal_number % 16;
            hexadecimal_number = hexadecimal_number + remainder * pow(10, count);
            decimal_number = decimal_number / 16;
            count++;
      }
      scanf("\nHexadecimal Equivalent:\t%d\n", hexadecimal_number);
      return 0;
getch();
}

15 comments:

  1. The algorithm is very easy. If to follow the structure, we can easily complete the task successfully. I think that everyone will be able to use this guideline to draw a line with endpoints.

    ReplyDelete
  2. it needs correction after__int count =0;
    there is printf() -- not scanf...
    and also in the last statement there is also printf()--not scanf ..

    ReplyDelete
  3. FA3AAA763CSantiago2D52549BCBNovember 25, 2024 at 9:37 PM

    31BB78D2E3
    show

    ReplyDelete

Let us know your responses and feedback