Skip to content

Instantly share code, notes, and snippets.

@rohit-nsit08
Created September 2, 2011 20:54
Show Gist options
  • Save rohit-nsit08/1189890 to your computer and use it in GitHub Desktop.
Save rohit-nsit08/1189890 to your computer and use it in GitHub Desktop.
pattern generation
#include<stdio.h>
int n;
void print(char *pattern,int index,int open,int close);
int main()
{
printf("enter the number of parantheses");
scanf("%d",&n);
static char pattern[100] ;
print(pattern,0,0,0);
return 0;
}
void print(char *pattern,int index,int open,int close)
{
if(close==n)
{
pattern[2*n]='\0';
printf("%s\n",pattern);
return;
}
if(open>close)
{
pattern[index] = '}';
print(pattern,index+1,open,close+1);
}
if(open<n)
{
pattern[index]='{';
print(pattern,index+1,open+1,close);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment