/************************************************************************
* Program: Converting Egyptian Fractions to Fraction *
* *
* File: Egy_lib.c ==> Library File for Egyptian Fraction *
* *
* *
*************************************************************************/
#include"Egy_head.h" //User-defined header file
void EgyFrac (egy_frac EGY, char *output_file) /* Calculation of Egyptian fractions */
{
res_frac Res_EGY;
int prod_den=1,sum_den=0,gcd_prod_sum_den;
int i,j;
int *p_units;
FILE *ofp;
ofp=fopen (output_file,"a+");
if (ofp == NULL)
{
perror("Output file\n");
exit(2);
}
for (i=0; i < EGY.no_units_fractions; i++)
{
prod_den = prod_den * EGY.p_den[i];
}
p_units = (int *)malloc(sizeof(int) * EGY.no_units_fractions);
if (p_units == NULL)
{
printf("Error in Data_units\n");
exit(3);
}
for (i=0; i < EGY.no_units_fractions; i++)
{
p_units[i] = prod_den
Library file for Egyptian fraction
This change has been discarded.
Header file for Egyptian Fraction | |
---|---|
1 | /**************************************************************** |
2 | * Program: Converting Egyptian Fractions to Fractions * |
3 | * * |
4 | * File: Egy_head.h ==> Header File for Egyptian * |
5 | * created on: 21-Aug * |
6 | * * |
7 | *****************************************************************/ |
8 | |
9 | |
10 | |
11 | #include<stdio.h> |
12 | #include<stdlib.h> |
13 | |
14 | |
15 | typedef struct egy_fractions /* No of unit fractions and points to denominator */ |
16 | { |
17 | int no_units_fractions; |
18 | int *p_den; |
19 | }egy_frac; |
20 | |
21 | typedef struct resultant_fraction /* Resultant of fraction numerator and denominator */ |
22 | { |
23 | int num; |
24 | int den; |
25 | }res_frac; |
26 | |
27 | |
28 | void EgyFrac (egy_frac ,char *); /* Calculating Egyptian fractions */ |
29 | |
30 | int Gcd (int , int ); /* Calculating the Gcd for prod_denominator and sum_denominator */ |