Home Forums C Programming convert decimal to binary

Viewing 1 reply thread
  • Author
    Posts
    • #2219
      saqib
      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
      GWILouisaxwzkla
      Participant

      could try this:

Viewing 1 reply thread
  • The forum ‘C Programming’ is closed to new topics and replies.