This is simple addition reader/parser for 2 doubles

This is simple addition reader/parser for 2 doubles





#include

/* function to read expression */
void
readex (double *op1, double *op2)
{
char plus;
/* no & required in scanf because &*op1 is the same thing as op1 */
scanf ("%lf %c %lf", op1, &plus, op2);
}



int
main(void)
{

double a, b, c;
printf ("Enter an addition expression (eg: 4.5+3.5): ");
/* the addresses of the two operands are sent to the function */
readex (&a, &b);
c = a + b;
printf("%lf + %lf is %lf.\n",a,b,c);

return(0);
}


No comments:

Post a Comment