Converting Decimal To Binary
Code:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1)
ll bin(ll num)
{
ll temp,i,s;
temp=num;
i=1;
s=0;
while(temp)
{
s+=(temp%2)*i;
i=i*10;
temp/=2;
}
return s;
}
int main()
{
ll num;
cin>>num;
cout<<bin(num)<<endl;
}
1234
10011010010
Process returned 0 (0x0) execution time : 2.942 s
Press any key to continue.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1)
ll bin(ll num)
{
ll temp,i,s;
temp=num;
i=1;
s=0;
while(temp)
{
s+=(temp%2)*i;
i=i*10;
temp/=2;
}
return s;
}
int main()
{
ll num;
cin>>num;
cout<<bin(num)<<endl;
}
Output:
1234
10011010010
Process returned 0 (0x0) execution time : 2.942 s
Press any key to continue.
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন