Hello to everyone as I am new and this is my first post.

My mother lenguage isn´t english but I´ll try my best to explain my self .

I am doing this program in which there is a function which is supposed to symplify a fraction such as 22/24 into 11/12.

The program doesn´t give any compilation errors but it only executes well when you introduce fractions like 24/36 and turns them into 2/3 because the highest common factor of both is found at the end of their vectors (va[c] and vb[c1]).

If this doubt I have has been discussed before please just send me to that thread.Code:#define d 15#include <stdio.h> int function1(int a, int b){ int va[d]={0}, vb[d]={0}; int i=0,j=0,c=0,c1=0,r,y; for(i=1;i<d;++i){if(a%i==0) {va[c]=i;++c;} if(b%i==0) {vb[c1]=i;++c1;}} printf("\nThe factor vectors are:\n"); for(i=0;i<d;++i)printf(" %d",va[i]); putchar('\n'); for(i=0;i<d;++i)printf(" %d",vb[i]); printf("\nValue in c: %d and in c1: %d",c, c1); /*This is where the problem must be*/ i=c-1; j=c1-1; while(i!=0){while(j!=0){ if(va[i]==vb[j]) return va[i]; else printf("\n\nva[%d]=%d != vb[%d]=%d",i,va[i],j,vb[j]); j=j-1; } i=i-1;} /*It should never return '98'. it should have returned '1' before becouse '1' is a factor of every number */ return 98; } int main(){int num, den,r; printf("Introduce your fraction´s numerator: "); scanf("%d", &num); printf("Introduce your fraction´s denominator: "); scanf("%d", &den); r=function1(num, den); printf("\nYour symplified fraction is: %d/%d", num/r, den/r); printf("\nResult picked up from function1 is: %d", r); return 0;}