By using the given source code I am trying to do some arithmetic operations. The given input is:
1
234*34
Since there is no space between 234
and *
and 34
, scanf
is not reading it properly. What should I do so that scanf
will read this input and give correct answer without providing the space between the input numbers?
#include <stdio.h>
int arithematic(){
int a,c,t,i=0,k,l;
char b[100];
scanf("%d%s%d",&a,&b[0],&c);
if(b[0] =='+')
t = a+c;
if(b[0] == '-')
t=a-c;
if(b[0]=='*')
t=a*c;
k=a;
l=c;
while(k>0||l>0)
{
k/=10;l/=10;
i++;
}
printf("%d\n",a);
printf("%s",b);
printf("%d\n",c);
while(i>0)
{
printf("-");
i--;
}
printf("\n%d\n",t);
}
int main(void)
{
int n;
scanf("%d",&n);
while(n--)
{
arithematic();
printf("\n");
}
}