Mình có bài tập phải viết chương trình đổi số thập phân sang nhị phân nhưng khi compile và nhận input thì nó không in ra số nhị phân + junk values, mong mọi người hướng dẫn cách fix.
Còn tại sao mình không viết chung vào hàm main thì tại vì đề bài nó yêu cầu vậy !
CODE của mình:
#include <stdio.h>
#include <stdlib.h>
void function1(int n)
{
printf("Convert Decimal to Binary program\n");
printf("\tEnter a positive number: ");
scanf("%d", &n);
while(n < 0)
{
printf("\tInvalid input\n\n");
printf("Convert Decimal to Binary program\n");
printf("\tEnter a positive number: ");
scanf("%d", &n);
}
}
void function2(int n, int numb[])
{
int i = 0;
while(n > 0)
{
numb[i] = n%2;
n = n/2;
}
}
void function3(int numb[])
{
int i, j;
printf("\tBinary number : ");
for(j = i - 1; j >= 0; j--)
{
printf("%d", numb[j]);
}
}
int main()
{
int n, numb[1000];
int i, j;
while(1)
{
function1(n);
function2(n, numb);
function3(n);
printf("\nPress any key continue\n\n");
getch();
}
return 0;
}

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?