Check Expression Contains Valid Parenthesis

Problem Statement:

Program to check whether given expression contains valid parenthesis or not.

Source Code:
#include<stdio.h>
int main(){
    char str[50],stack[50];
    int i,top=0,isvalid=1;
    fgets(str,50,stdin);
    for(i=0;str[i]!='\0';i++){
        if(str[i]=='('){
            stack[top++] = str[i];
        }else if(str[i]==')'){
            if(stack[top-1]=='('){
                top--;
            }else{
                isvalid = 0;
            }
        }
    }
    if(isvalid==1 && top==0)
        printf("Valid");
    else
        printf("Invalid");
    return 0;
}
SAMPLE INPUT1
((A*B)+(C/D)-E)
SAMPLE OUTPUT1
Valid

SAMPLE INPUT2
((A*B)+(C/D-E)
SAMPLE OUTPUT2
Invalid