#include<stdio.h> #include<conio.h> #include<string.h> int main(){ int i=0, top=-1; char s[30], stack[30]; clrscr(); printf("Enter expression :"); scanf("%s",&s); printf("%s",s); for(i=0;i<20;i++){ if((s[i]=='(')|| (s[i]=='{') || (s[i]=='[')){ top++; stack[top]=s[i]; }else if((stack[top]=='(' && s[i]==')')|| (stack[top]=='{' && s[i]=='}') || (stack[top]=='[' && s[i]==']')) { top--; } } if(top==-1){ printf("Valid Brackets"); }else{ printf("Invalid Brackets"); } getch(); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter