Skip to content

Instantly share code, notes, and snippets.

@ahmedeshaan
Last active August 29, 2015 14:15
Show Gist options
  • Save ahmedeshaan/f75dae9b5ae757ccd200 to your computer and use it in GitHub Desktop.
Save ahmedeshaan/f75dae9b5ae757ccd200 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int flag = 0,
output = 0,
loopInt = 0,
modulus = 0,
mutiplication = 0,
sum = 0;
//int square = 1;
void myBinary(int arg){
if(arg <= 0)
{
return 0;
}
modulus = arg % 10;
//printf("%d \n",arg);
arg /= 10;
// printf("%d \n",modulus);
if(flag == 0){
output = 1;
}
else
{
output = 1;
for(loopInt = 1; loopInt <= flag; loopInt++ )
{
output *= 2;
}
}
mutiplication = output * modulus;
sum += mutiplication;
printf("%d \n",sum);
flag++;
myBinary(arg);
}
int main()
{
int n=0;
scanf("%d",&n);
if(n <= 0)
{
n = -1*n;
}
myBinary(n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment