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.

, , 4 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();
}

4 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. Hayatımızda yeni şeyler öğrenmek ve kendimizi geliştirmek adına çeşitli yollar deniyoruz. Bu süreçte, farklı bakış açıları kazandıran ve ilham veren eserler oldukça önemli oluyor. Özellikle, ilginizi çekebilecek kitap önerileri sayesinde, okuma alışkanlığınızı geliştirebilir ve yeni dünyalara adım atabilirsiniz. Bu nedenle, kendinizi sürekli olarak yenilemek ve genişletmek adına okuma listelerinize mutlaka eklemelisiniz.

    ReplyDelete

Let us know your responses and feedback