I am newly learned,
Is the most basic statement,
The program function is not perfect,
Have the following questions,
1. Big data cannot be calculated,
2. Large integer data output is floating point type, (because it is the job assigned by the teacher, there is a requirement that the arithmetic calculation output containing the real number should contain decimals.) )
3. Unable to use () to raise the priority of the operation,
Welcome suggestions for Improvement
The code is attached:
void Fun1 ()//arithmetic operation function
{
Char a[20][30],b[20];
Double c[20],s;
int I,j,k,flag;
System ("CLS");//
printf ("Input arithmetic \ n format such as: 31+42*21/43-2\n return output operation result.");
bo=
Fflush (stdin);
flag=0;
System ("pause");
System ("CLS");
for (i=0; i<20; i++)//Looping statement input
{
K=i;
for (j=0;; j + +)
{
A[i][j]=getchar ();///character array each row holds a string of numbers with an operator or carriage return
if (a[i][j]== ' \ n ' | | a[i][j]== ' + ' | | a[i][j]== '-' | | a[i][j]== ' * ' | | a[i][j]== '/')
{
B[I]=A[I][J];
a[i][j+1]= ' + ';
Break
}
}
if (b[i]== ' \ n ') break;
}
for (i=0; i<=k; i++)//Determine if the input is legal
{
if (! ( a[i][0]<= ' 9 ' &&a[i][0]>= ' 0 ' | | a[i][0]== ' \ n '))
flag=1;
for (j=0; a[i][j+1]!= '; j + +)
{
if (! ( a[i][j]<= ' 9 ' &&a[i][j]>= ' 0 ' | | a[i][j]== ' \ n '))
flag=1;
if (flag) break;
}
if (flag) break;
}
if (flag) printf ("Input error, please re-enter!") \ n ");
}
while (flag);
for (i=0; i<=k; i++)//Determine if the input number has a floating-point type
{
for (j=0; j<10; j + +)
if (a[i][j]== '. ') flag=1;
C[i]=atof (A[i]);//Converts a numeric character in a string to a floating-point type
}
for (i=0; b[i]!= ' \ n '; i++)//calculated based on priority multiplication
{
Switch (B[i])
{
Case ' * ':
C[I]*=C[I+1];
C[i+1]=c[i];
for (j=i; j!=0; j--)
{
if (b[j-1]== ' * ' | | b[j-1]== '/')
C[J-1]=C[J];
else break;
}
Break
Case '/':
C[I]/=C[I+1];
C[i+1]=c[i];
for (j=i; j!=0; j--)
{
if (b[j-1]== ' * ' | | b[j-1]== '/')
C[J-1]=C[J];
else break;
}
Break
}
}
S=C[0];
for (i=0; b[i]!= ' \ n '; i++)
Switch (B[i])
{
Case ' + ':
S+=C[I+1];
Break
Case '-':
S-=C[I+1];
Break
}
if (!flag)//integer float type judgment
if (! ( s== (int) s)) flag=1;
if (!flag) printf ("%d\n", (int) s);//Determine whether the output is floating-point or shaped and output
else printf ("%f\n", s);
System ("pause");
}
Simple Calculator C language source code,