dos_compilers/Borland Turbo C++ v1/EXAMPLES/INTRO2.C
2024-07-02 07:34:51 -07:00

25 lines
588 B
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* INTRO2.C--Example from Chapter 4 of User's Guide */
#include <stdio.h>
int main()
{
char inbuf[130];
float num, denom; /* numerator and denominator of fraction */
float value; /* value of fraction as decimal */
printf("Convert a fraction to a decimal\n");
printf("Numerator: ");
gets(inbuf);
sscanf(inbuf, "%f", &num);
printf("Denominator: ");
gets(inbuf);
sscanf(inbuf, "%f", &denom);
value = num / denom; /* convert fraction to decimal */
printf("\n %f / %f = %f", num, denom, value);
return 0;
}