Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- double getstr(int bgn, int nd, char *str){
- char nstr[128]="";
- for(int i=bgn; i<nd; i++){
- nstr[i-bgn]=str[i];
- }
- return atof(nstr);
- }
- double act(double CurrentC, float NewC, char sym[1]){
- if(sym[0]=='-') return CurrentC-NewC;
- if(sym[0]=='+') return CurrentC+NewC;
- if(sym[0]=='/') return CurrentC/NewC;
- if(sym[0]=='*') return CurrentC*NewC;
- return 0;
- }
- int main(){
- char m[256];
- char CurrentType[1]="+";
- int CurrentTypeValue=0;
- double LastValue=0.0;
- scanf("%s",m);
- for(int i=0; i<strlen(m); i++){
- if(m[i]=='-' || m[i]=='+' || m[i]=='/' || m[i]=='*' || m[i+1]=='\0'){
- if(i==0){
- CurrentType[0]=m[i];
- CurrentTypeValue++;
- }
- else if(m[i+1]=='\0'){
- printf("%.2f\n", act(LastValue, getstr(CurrentTypeValue, i+1, m), CurrentType));
- }
- else{
- LastValue=act(LastValue, getstr(CurrentTypeValue, i+1, m), CurrentType);
- CurrentType[0]=m[i];
- CurrentTypeValue=i+1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement