Calculation of Egyptian Fraction

Review Request #6287 — Created Sept. 3, 2014 and discarded

Information

Reviewers

Need the code review for this Egyptian Fraction Program for more specific code.

Code is giving the correct output. No bugs is there.

					/****************************************************************
					*	Program: Converting Egyptian Fractions to Fractions   	*
					*								*
					*	File: Egy_head.h ==> Header File for Egyptian		*
					*	created on: 21-Aug					*
					*								*
					*****************************************************************/
#include<stdio.h>		
#include<stdlib.h>
typedef struct egy_fractions		/* No of unit fractions and points to denominator 		*/
{
	int no_units_fractions;
	int *p_den;
}egy_frac;
typedef struct resultant_fraction	/* Resultant of fraction numerator and denominator 		*/
{
	int num;
	int den;
}res_frac;
void EgyFrac (egy_frac ,char *);	/* Calculating Egyptian fractions 				*/
int Gcd (int , int );  			/* Calculating the Gcd for prod_denominator and sum_denominator */
					/************************************************************************
					*	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 
					/************************************************************************
					*	Program: Converting Egyptian Fractions to Fractions		*
					*									*
					*	File: Egy_app.c ==> Main File for Egyptian			*
					*									*
					*									*
					*************************************************************************/
#include"Egy_head.h"	
int main(int argc, char *argv[])
{
	egy_frac egy_ip ;
	int no_instances;
	int i,j;
	FILE *ifp;
	if (argc != 3)
	{
		printf("Insufficient data\n");
		return 0;
	}
	ifp = fopen(argv[1],"r");
	if (ifp==NULL)
	{
		perror("open");
		exit(1);
	}
	fscanf(ifp,"%d",&no_instances);				/* No of instances  */
	for (j=0;j<no_instances;j++)
	{
		fscanf(ifp,"%d",&egy_ip.no_units_fractions);	/* No of units fractions */
		egy_ip.p_den = (int *)malloc( sizeof(int) * egy_ip.no_units_fractions );
		if (egy_ip.p_den == NULL)
		{
			perror("Error in allocating space\n");
			exit(2);
		}
		for (i=0;i<egy_ip.no_units_fractions;i++)
		{
			fscanf(ifp,"%d",eg

YA
  1. I am going through this code. But i need more spcific code.

  2. 
      
YA
david
  1. Please don't use this server for testing. If you want to try out Review Board, you can use https://demo.reviewboard.org

  2. 
      
YA
Review request changed
Status:
Discarded
Loading...