Đây là bài làm của mình. Ko biết sai ở đâu nữa :(
Code:
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int n;
void doc(char *name)
{
FILE *f;
f=fopen(name,"r");
if(f==NULL)
{
puts("loi mo tep");
getch();
exit(0);
}
else
fscanf(f,"%d",&n);
}
void doisonhiphan()
{
FILE *f;
f=fopen("tam.out","w");
if(f==NULL)
{
puts("loi mo tep");
getch();
exit(0);
}
int b;
int c[100];
int j,i;
printf("%d",n);
for (int k =0;k<=n;k++)
{
b=k;
printf("%d",b);
i=0;
while(b!=0)
{
c[i]=b%2;
b=b/2;
i++;
}
for(j=i-1;j>=0;j--)
fprintf(f,"%d",c[j]);
fprintf(f,"\n");
}
}
int main()
{
doc("tam.inp");
doisonhiphan();
//printf("%d",n);
getch();
}