Skip to content

Instantly share code, notes, and snippets.

@tarcisio-marinho
Last active October 25, 2016 05:09
Show Gist options
  • Save tarcisio-marinho/86c4d13f80bddb9d69923a6c9d0c9b9b to your computer and use it in GitHub Desktop.
Save tarcisio-marinho/86c4d13f80bddb9d69923a6c9d0c9b9b to your computer and use it in GitHub Desktop.
4th bit de um numero inteiro
#include<stdio.h>
void binary(int array[]){
int n,i,j,a;
i=0;
scanf("%d",&n);fflush(stdin);
if(n<8){
printf("0\n");
}else if(n==8){
printf("1\n");
}
else{
while(n>0){
array[i]=n%2;
n/=2;
++i;
}
for(j=i-1;j>=0;--j){
a++;
if(a==4){
printf("%d",array[j]);
}
}printf("\n");
}
}
int main(){
int array[100]={0};
binary(array);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment