Write a program in C++ to convert a decimal number to binary number

  • برمجة سي بلس بلس
  • برمجة

Write a program in C++ to convert a decimal number to binary number

Sample Output:

 Convert a decimal number to binary number:                            
---------------------------------------------------                    
 Input a decimal number: 35                                            
 The binary number is: 100011

الأجوبة

#include <iostream>
#include <math.h>
using namespace std;
 
int main()
{
        int dec_num, rem, quot, i=1, j;
        int bin_num[100];

		cout << "\n\n Convert a decimal number to binary number:\n";
	cout << "---------------------------------------------------\n";
	cout << " Input a decimal number: ";
	cin>> dec_num;
        quot = dec_num;
        while(quot != 0)
        {
            bin_num[i++] = quot%2;
            quot = quot/2;
        }
        cout<<" The binary number is: ";
        for(j=i-1; j>0; j--)
        {
            cout<<bin_num[j];
        }
   cout<<("\n");  
 }  
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...