I have an assignment to write a program that converts decimal numbers to binary numbers, in the C programming language.
This is the code I wrote:
#include <stdio.h>
#define MAX_LEN 1000
void translate_dec_bin(char s[]){
unsigned int decNum;
sscanf_s(s, "%d", &decNum);
while (decNum > 0){
printf("%d", decNum % 2);
decNum = decNum / 2;
}
printf("\n");
}
main(){
char s[MAX_LEN];
char c='\0';
int count=0;
printf("enter a nunber\n");
while (c < MAX_LEN && ((c = getchar()) != EOF) && c != '\n'){
s[count] = c;
++count;
}
translate_dec_bin(s);
}
However, when the input is 1, the output I get is 1 instead of 0001. In other words, I want the 0's to appear in my output. How can I do that?