Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <stack>
- #include <stdio.h>
- using namespace std;
- int main()
- {
- char exp[100];
- char valid[] = "1234567890+-*/()^";
- int i,x=0,y=0;
- stack <char> myStack;
- cout << "Input the Expression: ";
- gets(exp);
- for(i=0; exp[i] != '\0'; i++)
- {
- myStack.push(exp[i]);
- }
- while(!myStack.empty())
- {
- for(i=0; valid[i] != '\0'; i++)
- {
- if(myStack.top()==valid[i])
- {
- x =1;
- }
- }
- if(x==1)
- {
- myStack.pop();
- continue;
- }
- else
- {
- cout << "Invalid Arithmetic Expression"<<endl;
- y=1;
- break;
- }
- }
- if(y==0)
- {
- cout << "Valid Arithmetic Expression"<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement