#include <stdio.h>
int nzd(int n,int m)
{
int nzd;
while (n % m)
{
nzd = n % m;
n = m;
m = nzd;
}
return nzd;
}
//Greatest common divisor
int nzsf(int a, int b){
int nzs;
nzs = (a * b)/nzd(a, b);
return nzs;
}
//smallest common multiple
int skrati(int *a,int *b,int c,int d)
{
while (*a!=c&&*b!=d)
{
*a/=nzd(*a,*b);
*b/=nzd(*a,*b);
}
}
/*where the problem lies,the functions supposed to shorten the fraction of a/b to an unshortened fraction of c/d*/
int main()
{
int *a,*b,c,d, nzd1;
scanf("%d%d%d%d",&*a,&*b,&c,&d);
nzd1=nzd(*a,*b);
if ((nzd1)==1)
printf("Numbers are coprime integers");
else{
printf("%d",nzd1);
printf("%d",nzd(nzd1,c));
skrati(&a,&b,c,d);
printf("Test %d %d",a,b);
}
return 0;
}
#pointer help
11 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
pretty sure the problem is somewhere in main when im calling the pointers because before i switched from normal integers to pointers it worked fine
int *a,*b,c,d, nzd1;
scanf("%d%d%d%d",&*a,&*b,&c,&d);
This is wrong
What you have to remember is that pointers need to point to some variable/memory address
Here a and b are defined as pointers, but where they point to are never defined
int a,b,c,d, nzd1;
scanf("%d%d%d%d",&a,&b,&c,&d);
// ...
skrati(&a,&b,c,d);
@shy abyss Has your question been resolved? If so, run !solved :)
!solved