IHYPRESS.NET > C PROGRAMMING
HOME | CLASSIC ASP | C | HTML/CSS | JAVASCRIPT | PERL | PHP | PYTHON | RUBY
C > 06. Functions II (Pointers) [PROGRAM #07]
CODERESULT
<
/* Problem: This is simple addition reader/parser for 2 doubles.  */

#include <stdio.h>

/* 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);
}
/* can you expand this program to cover substractions? */
Legend: preprocessor directives | variable declarations main function | helper functions | user-defined structures comments
Enter an addition expression (eg: 4.5+3.5): 13.4+5.6
13.400000 + 5.600000 is 19.000000.
 
COPYRIGHT © 2021 IHYPRESS.NET. A DIVISION OF IHY PRESS, KIRKLAND, WA 98083 USA. ALL RIGHTS RESERVED.