0% found this document useful (0 votes)
3 views2 pages

1

The document contains a C program that evaluates mathematical expressions input by the user, requiring an '=' sign at the end. It processes the input to perform operations such as addition, subtraction, multiplication, and division while handling zero division errors. The program updates the results dynamically and prints intermediate results until the final output is achieved.

Uploaded by

sthanischhal207
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

1

The document contains a C program that evaluates mathematical expressions input by the user, requiring an '=' sign at the end. It processes the input to perform operations such as addition, subtraction, multiplication, and division while handling zero division errors. The program updates the results dynamically and prints intermediate results until the final output is achieved.

Uploaded by

sthanischhal207
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>
#include <stdlib.h>
#include <string.h>

void results(int C);


void update(int i,int C);

char equation[100],symbols[100];
float num[100];
int main()
{
int i=0;
printf("NOTE: DONT FORGET TO ENTER = SIGN AT THE END OF EXPRESSION\n");
printf("Enter the expression: \n");
while(symbols[i-1] != '=')
{
scanf("%f",&num[i]);
scanf("%c",&symbols[i]);
i++;
}
results(strlen(symbols));
return 0;
}

float result;

void results(int C)
{
int i;
for(i=0;i<C;i++)
{
if(symbols[i] == '/')
{
if(num[i+1]==0)
{
printf("----zero division error----");
exit(1);
}
result = num[i]/num[i+1];
update(i,C);
}
}

for(i=0;i<C;i++)
{
if(symbols[i] == '*')
{
result = num[i]*num[i+1];
update(i,C);
}
}

for(i=0;i<C;i++)
{
if(symbols[i] == '+')
{
result = num[i]+num[i+1];
update(i,C);
}
}

for(i=0;i<C;i++)
{
if(symbols[i] == '-')
{
result = num[i]-num[i+1];
update(i,C);
}
}
}

void update(int i,int C)


{
int j;
num[i]=result;
for(j=i+1;j<C;j++)
{
num[j]=num[j+1];
}
for(j=i;j<=C;j++)
{
symbols[j]=symbols[j+1];
}
for(j=0;j<C-1;j++)
{
printf("%g ",num[j]);
if(symbols[j]!='=')
{
printf("%c ",symbols[j]);
}
}
printf("\n");
results(C-1);
}

You might also like