0% found this document useful (0 votes)
9 views3 pages

Lab Task 10 PF Nimra

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Lab Task 10 PF Nimra

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

National University of Modern

Languages

Name :
Nimra Azeem
Class:
BSCS
NUML Id:
NUML-F24-39415
Semester:
1st
Subject:
Programming Fundamentals

Submitted To:
Sir Shahroz Tariq
Lab task no 10
Write a program in C++ to convert a decimal number to a binary number using the function.

Code:

#include<iostream>
using namespace std;
void decimalToBinary(int decimalNumber)
{
cout<<"Binary of "<<decimalNumber<<" = ";
int binary[100];
int index=0;
for(int i=0;i<100;i++)
{
binary[index++]=decimalNumber%2;
decimalNumber/=2;
if(decimalNumber==0)
{
break;
}
}
for(int i=index-1;i>=0;i--)
{
cout<<binary[i];
}
cout<<endl;
}
int main()
{
int i,decimalNumber;
int bin[100];
int index=0;
cout<<"Enter Decimal Number= ";
cin>>decimalNumber;
if(decimalNumber==0)
{
cout<<"Binary : 0"<<endl;
}
else
{
decimalToBinary(decimalNumber);
}
}

Output:

You might also like