home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 7.img / EXAMPLES.ZIP / INTRO2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  591 b   |  25 lines

  1. /* INTRO2.C--Example from Chapter 4 of Getting Started */
  2.  
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7.    char  inbuf[130];
  8.    float num, denom;     /* numerator and denominator of fraction */
  9.    float value;          /* value of fraction as decimal */
  10.  
  11.    printf("Convert a fraction to a decimal\n");
  12.    printf("Numerator: ");
  13.    gets(inbuf);
  14.    sscanf(inbuf, "%f", &num);
  15.    printf("Denominator: ");
  16.    gets(inbuf);
  17.    sscanf(inbuf, "%f", &denom);
  18.  
  19.    value = num / denom;  /* convert fraction to decimal */
  20.  
  21.    printf("\n %f / %f  = %f", num, denom, value);
  22.  
  23.    return 0;
  24. }
  25.