Decimal to binary converter

Page 1

THE UNIVERSITY OF DODOMA

College Of Informatics and Virtual Education

NAME: Makame, Makame H REGISTRATION No: T/UDOM/2010/00410 PROGRAM: B Sc. Computer and Information Security

ASSIGNMENT NO.2

COURSE NAME: Data Structure and Organization COURSE CODE: CS 104 COUSE INSTRUCTOR: Masoud Masoud

Question: Write a program to convert decimal numbers to binary.


Program #include<iostream.h> #include<conio.h>

void main() { int q, n; // q gives the quotient and n the numerator int r[9]; // r collects the remainders int i=0 ; // i the index of array r

cout<<"Enter a number" <<"\t"; cin >>n; cout<<endl <<endl;

do { q=(n/2); r[i]=(n%2); n=q; i++; }while(n!=0);


for(int j=i-1; j>=0; j--) { cout<<r[j]<<"\t"; } getch();

}


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.