#include<stdio.h>
void dec_to_bin(int n)
{
int arr[31],len = 0,i;
if(n == 0)
{
arr[0] = 0;
len = 1;
}
while(n != 0)
{
arr[len++] = n % 2;
n /= 2;
}
for(i=len-1; i>=0; i--)
printf("%d",arr);
}
int main()
{
int n = 0;
dec_to_bin(n);
return 0;
}
a) O(1)
b) O(n)
c) O(n2)
d) O(logn)
What is the time complexity of the following code used to convert a decimal number to its binary equivalent?
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
What is the time complexity of the following code used to convert a decimal number to its binary equivalent?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!