convert decimal to binary

Home Forums C Programming convert decimal to binary

This topic contains 1 reply, has 2 voices, and was last updated by  GWILouisaxwzkla 10 years, 3 months ago.

  • Author
    Posts
  • #2219

    Alfredo97J
    Participant

    i have written a programme to convert decimal to binary….if i giv input as 25, i am getting 791 as output………i am not able to find the error…tried alot….please check the code n say where is d error…n giv me a solution…….

    CODE
    #include #include
    void main()
    {
    int n,j,k,c=0;
    int m=0;
    int a[20];
    printf(“enter the decimal no: “);
    scanf(“%d”,&n);
    while(n>0)
    {

    L:
    j=n%2;
    k=n/2;
    n=k;
    c++;
    if(m!=c)
    {
    a[m]=j;
    m++;
    }
    if(k!=0)
    {
    goto L;
    }
    else
    {
    break;
    }
    }
    printf(“the equivalent binary no is “%d””,a[m]);
    }
    getch();
    }

  • #3600

    could try this:

You must be logged in to reply to this topic.

Share
Tweet
Share
Pin