Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tiny calculator

3 views
Skip to first unread message

Takanori Oshiro

unread,
Jul 7, 2021, 7:54:07 AM7/7/21
to
In order to record balance sheet on android terminal
tiny calculator becomes to be needed
Please refer to source code about detail
#include <stdio.h>
#include <stdlib.h>
int main(){
char buf[80];
char operator;
char str1[80];
char str2[80];
int datum1;
int datum2;
int i,j;

while(1){
i=j=0;
scanf("%s",buf);
while(buf[i] != '+' && buf[i] !='-')
str1[j++]= buf[i++];
str1[j+1] = '\0';
operator = buf[++i];
j=0;
while(buf[i]!='\0')
str2[j++]=buf[i++];
str2[j+1]='\0';
datum1 = atoi(str1);
datum2 = atoi(str2);
if(operator=='+')
printf("%d\n",datum1+datum2);
else
printf("%d\n",datum1-datum2);
}
}
0 new messages