Using structures to find the GCD of a fraction (Simple C program) -


as title says, i'm making program find gcd of fraction. program has function find it, had run problems.

i want function accept 2 structure variables (denominator , numerator) , returns gcd (integer)

here's code:

#include <stdio.h>   struct fraction{     int numerator,denominator; };  int find_gcd(struct fraction s1, struct fraction s1);  int main(void) {     struct fraction d1;     int gcd;      d1.numerator= 20;     d1.denominator= 100;      printf("fraction: %d/%d\n",d1.numerator,d1.denominator);      gcd= find_gcd(d1.numerator, d1.denominator);     printf("in lowest terms: %d/%d",d1.numerator/gcd,d1.denominator/gcd); }  int find_gcd(struct fraction s1, struct fraction s1) {     int remainder=0;      while (s1.denominator !=0)     {         remainder = s1.numerator/s1.denominator;         s1.numerator= s1.denominator;         s1.denominator= remainder;     }      return s1.numerator;        //this gcd } 

i following errors:

gcd_structures.c:8:50: error: redefinition of parameter 's1'  int find_gcd(struct fraction s1, struct fraction s1);                                                   ^ gcd_structures.c:8:30: note: previous definition of 's1' here  int find_gcd(struct fraction s1, struct fraction s1);                               ^ gcd_structures.c: in function 'main': gcd_structures.c:20:10: error: incompatible type argument 1 of 'find_gcd'      gcd= find_gcd(d1.numerator, d1.denominator); 

any appreciated.

in signature of function, both of parameters named s1

fix that, perhaps renaming 1 of parameters s2


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -