shravanreddynallabolu
BAN USER- 2 Answers program for user algebra
Hello....
- shravanreddynallabolu December 19, 2013
I am trying this from 4 days but i cannot be able to get the correct result......the problem is....
The user enters the algebraic expression with +,-,(,),/,a,b,c
and so the values of a,b,c...the program must show him the result of the expression....for example, Enter your expression a+(b/c)+ac
enter the values for a
4
enter the values for b
25
enter the values for c
5
result=29
please give me the code
#include<stdio.h> #include<conio.h> void main(){ int a,b,c,i,j,r=1; char ch[10]; clrscr(); printf("enter your expression\n"); gets(ch); i=0; while(i<=strlen(ch)-1) { if(ch[i]=='a') { printf("enter the a value"); scanf("%d",&a); } else if(ch[i]=='b') { printf("enter b value"); scanf("%d",&b); } else if(ch[i]=='c') { printf("enter c value"); } if(ch[i]=='+'||ch[i]=='-'||ch[i]=='('||ch[i]==')'||ch[i]=='/') { i++; } } j=strlen(ch)-1; while(/* DONT KNOW WHAT CONDITION I MUST GIVE */) { r=ch[j]*r; j--; } }
upto here i've written and in the second while loop i am getting a problem as the calculation is performing for each j--; suppose if the array is 4 + ( 25 / 5 ) + 4 5 as j=strlen(ch)-1; therefore ch[j]=5 and r is r=5*1 next j decrements and ch[j]=4 and r becomes 5*4 20 and so on................
but, the calculation must be performed according to the operator precedence i mean division operator has more prior then others and my result is getting wrong........| Flag | PURGE