| |
/*
This code converts a fraction into it's decimal representation -
fraction.c
Code updated (08/02/2001) to use return value from scanf(), this
will catch input errors */
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int numerator = 0,
denominator = 0,
ret_val
= 0;
while (ret_val != 2)
{ /*
Get input from keyboard. */
printf("Enter a fraction,
two whole numbers separated by a / (i.e 3/4) - ");
scanf("%d/%d",&numerator
,&denominator);
}
printf("%d/%d = %f ",numerator ,denominator
,(float)numerator/denominator ");
return EXIT_SUCCESS;
} |
|