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();

}

Decimal to binary converter  

This program to converts decimal numbers to binary.

Read more
Read more
Similar to
Popular now
Just for you