C Programming / Decimal to Binary

Standard

Have you ever heard this? after a month of not posting here i’m gonna change my topic into programming languages. Well i’m a Software Engineer student and i need to learn this, i need to study hard and REST MY NAILS FIRST 🙂 (or if i’m in the mood still posting nails haha can’t resist)

I will post my codes so i can share my school works, oginally from me. Can copy and paste so that your life makes more easier thinking about those fucking crazy codes.

One of my sample code is Decimal converting into Binary using simple Loops.

# include <iostream>

using namespace std;

int main()

{

int b[20], n, r, c = 0, i ;

cout<<“Enter a decimal number : ” ;

cin>>n ;

while(n > 0)

{

r = n % 2 ;

b[c] = r ;

n = n / 2 ;

c++ ;

}

cout<<“\nThe binary equivalent is : “;

for(i = c – 1 ; i >= 0 ; i–)

cout<<b[i] ;

system(“pause>0”);

}

OUTPUT:

Enter a decimal number: 10

The binary equivalent is: 1010

Advertisements

Leave a Reply Like You Care ♥

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s