Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Function to find the binary equivalent of a given decimal integer and display it

Posted By: Adelchi Fischer     Category: C Programming     Views: 12267

Write a function to find the binary equivalent of a given decimal integer and display it.

Code for Function to find the binary equivalent of a given decimal integer and display it in C Programming

       # include<stdio.h>
       void main()
       {
           int n;
           void binary(int);  // Function Declaration
           clrscr();
           printf("Enter any Decimal Number : ");
           scanf("%d",&n);
           binary(n);         // Function Calling
           getch();
       }
       void binary(int x)         // Function Definition.
       {
           char s[20];
           int i,t;
           t=x;
           i=0;
           while(t>0)
           {
               s[i]=t%2;
               t=t/2;
               i++;
           }
           s[i]='\0';
           printf("Binary Equivalent of %d = ",x);
           for(i=i-1;i>=0;i--)
               printf("%d",s[i]);
       }
  
Share: 



Adelchi Fischer
Adelchi Fischer author of Function to find the binary equivalent of a given decimal integer and display it is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!