dos_compilers/Borland Turbo C++ v1/EXAMPLES/INTRO2.C

25 lines
588 B
C++
Raw Normal View History

2024-07-02 16:34:51 +02:00
/* 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;
}