0
I am trying to program a simple program that reads a number in base ten and converts it to binary and I have reached the following code:
#include <stdio.h>
#include <math.h>
int main(){
int n;
int c = 1;
scanf("%d", n);
while(n>=c){
int digit = (n/c)%2;
printf("%d", digit);
c *= 2;
}
}
I am aware that the number will be printed backwards, my problem is that after compiling the code (which happens without any error), the program always crashes when I try to open. When I used an online compiler, however, the output I got was "Segmentation fault (core dumped)". Can anyone explain to me what’s going on?
Possible duplicate of What is Segmentation fault?
– Woss