===========================================================================
CODING
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<math.h>
void solve(char str[10][80],int &SOLVE)
{
int i,j,k,len,a,b;
for(i=0;str[0][i]!='\0';i++);
len=i-1;
for(i=0,a=0;len>=0;i++,len--)
a=a+(str[0][i]-48)*pow(10,len);
for(i=0;str[2][i]!='\0';i++);
len=i-1;
for(i=0,b=0;len>=0;i++,len--)
b=b+(str[2][i]-48)*pow(10,len);
if(str[1][0]=='+')
SOLVE=a+b;
else if(str[1][0]=='-')
SOLVE=a-b;
else if(str[1][0]=='*')
SOLVE=a*b;
else if(str[1][0]=='\/')
SOLVE=a/b;
else
{
cout<<"ERROR";
exit(0);
}
}
void main()
{
clrscr();
char str[10][80],c;
int i,j,k,count,SOLVE;
for(count=0,i=0,j=0;1==1;)
{
c=getch();
if(c=='=')
{
solve(str,SOLVE);
i++;
j=0;
str[i][j]=c;
str[i][j+1]='\0';
i++;
sprintf(str[i],"%d",SOLVE);
clrscr();
cprintf("%s%s%s%s%s",str[0],str[1],str[2],str[3],str[4]);
getch();
exit(0);
}
else if(c=='+' || c=='-' || c=='\/' || c=='*')
{
count++;
if(count==1)
{
str[i][j]='\0';
i++;
j=0;
str[i][j]=c;
str[i][j+1]='\0';
i++;
j=0;
str[i][j]='\0';
}
else if(count==2)
{
i=0;
solve(str,SOLVE);
sprintf(str[i],"%d",SOLVE);
i++;
j=0;
str[i][j]=c;
str[i][j+1]='\0';
i++;
j=0;
str[i][0]='\0';
count=1;
}
}
else
{
str[i][j]=c;
j++;
str[i][j]='\0';
}
clrscr();
if(count==0)
cprintf("%s",str[0]);
else if(count==1)
cprintf("%s%s%s",str[0],str[1],str[2]);
}
getch();
}
CODING
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<math.h>
void solve(char str[10][80],int &SOLVE)
{
int i,j,k,len,a,b;
for(i=0;str[0][i]!='\0';i++);
len=i-1;
for(i=0,a=0;len>=0;i++,len--)
a=a+(str[0][i]-48)*pow(10,len);
for(i=0;str[2][i]!='\0';i++);
len=i-1;
for(i=0,b=0;len>=0;i++,len--)
b=b+(str[2][i]-48)*pow(10,len);
if(str[1][0]=='+')
SOLVE=a+b;
else if(str[1][0]=='-')
SOLVE=a-b;
else if(str[1][0]=='*')
SOLVE=a*b;
else if(str[1][0]=='\/')
SOLVE=a/b;
else
{
cout<<"ERROR";
exit(0);
}
}
void main()
{
clrscr();
char str[10][80],c;
int i,j,k,count,SOLVE;
for(count=0,i=0,j=0;1==1;)
{
c=getch();
if(c=='=')
{
solve(str,SOLVE);
i++;
j=0;
str[i][j]=c;
str[i][j+1]='\0';
i++;
sprintf(str[i],"%d",SOLVE);
clrscr();
cprintf("%s%s%s%s%s",str[0],str[1],str[2],str[3],str[4]);
getch();
exit(0);
}
else if(c=='+' || c=='-' || c=='\/' || c=='*')
{
count++;
if(count==1)
{
str[i][j]='\0';
i++;
j=0;
str[i][j]=c;
str[i][j+1]='\0';
i++;
j=0;
str[i][j]='\0';
}
else if(count==2)
{
i=0;
solve(str,SOLVE);
sprintf(str[i],"%d",SOLVE);
i++;
j=0;
str[i][j]=c;
str[i][j+1]='\0';
i++;
j=0;
str[i][0]='\0';
count=1;
}
}
else
{
str[i][j]=c;
j++;
str[i][j]='\0';
}
clrscr();
if(count==0)
cprintf("%s",str[0]);
else if(count==1)
cprintf("%s%s%s",str[0],str[1],str[2]);
}
getch();
}
===========================================================================
No comments:
Post a Comment