Header Ads Widget

Program to print all binary string of n length .

program:-

#include<stdio.h>
void main()
{
void bin(int ,char[]); // function declaration
int l;
char s[100];
printf("Enter the length of string ");
scanf("%d",&l);
s[l]='\0';
bin(l,s); // function calling
}

// function definition


void bin(int n,char s[])
{
if(n<1)
{
printf("%s\n",s);
}
else
{
s[n-1]='0';
bin(n-1,s);
s[n-1]='1';
bin(n-1,s);
}
}