TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jitendra Kumar
NA
189
22.9k
How to do this dynamical. Then I can put the value of myself
Aug 22 2018 2:49 AM
class Program
{
static void Main(string[] args)
{
Stack Stack = new Stack();
string[] expression = { "10", "1","2","+","2","+","5","+", "+" };
for (int i = 0; i < expression.Length; i++)
{
Console.Write(expression[i]);
}
int result;
Console.WriteLine();
int n;
foreach (string c in expression)
{
if (int.TryParse(c, out n))
{
Stack.Push(n);
}
if (c == "+")
{
int x = Convert.ToInt32(Stack.Pop());
int y = Convert.ToInt32(Stack.Pop());
result = x + y;
Stack.Push(result);
}
if (c == "-")
{
int x = Convert.ToInt32(Stack.Pop());
int y = Convert.ToInt32(Stack.Pop());
result = y - x;
Stack.Push(result);
}
if (c == "*")
{
int x = Convert.ToInt32(Stack.Pop());
int y = Convert.ToInt32(Stack.Pop());
result = x * y;
Stack.Push(result);
}
if (c == "/")
{
int x = Convert.ToInt32(Stack.Pop());
int y = Convert.ToInt32(Stack.Pop());
result = y / x;
Stack.Push(result);
}
}
Console.WriteLine("enter any postfix expression");
Console.WriteLine("result of expression: {0}", Stack.Peek());
Console.ReadLine();
}
}
Reply
Answers (
0
)
How to check the conditions in storedprocedure
stored procedure in sqlserver