Monday, April 1, 2013

Trying printf and scanf

A program that asks the user for two numbers and prints out the sum and the product.


/* Trying printf and scanf */
#include <stdio.h> int main (void) { /* declarations */ double x, y, z; /* executable statements */ printf ("Enter two real numbers: "); scanf ("%lf %lf", &x, &y); z = x + y; printf ("\nThe sum of %lf and %lf is %f.\n", x, y, z); printf ("\nThe product of %lf and %lf is %lf.\n", x, y, x*y); return (0); }
Legend: preprocessor directives | variable declarations | main program | helper functions | user-defined structures | comments
Enter two real numbers: 45.9 432.457
The sum of 45.900000 and 432.457000 is 478.357000.
The product of 45.900000 and 432.457000 is 19849.776300.

No comments:

Post a Comment