I am trying to write a code for a problem in C. The code is as follows:
#include<stdio.h>
int cop(int a,int b)
{
int c,d,e,f,g;
if(a>b)
{
c=a;
a=b;
b=c;
}
while(c!=0)
{
c=b%a;
b=a;
a=c;
}
return b;
}
int main()
{
int i=1, j=1, k, a, b, c, d, e, f, g=1;
scanf("%d",&k);
int q=0;
for(q=k;q>0;q--)
{
scanf("%d",&a);
while(g==1)
{
b=j+i;
i=j;
j=b;
g=cop(j,a);
printf("%d\n",g);
}
printf("%d %d\n",g,j);
j=1;i=1;g=1;
}
return 0;
}
When I give input as 3 3 5 161
it was printing
1
3
3 3
1
1
5
5 5
1
1
1
1
1
7
7 21
and when i comment out the statement printf("%d\n",g)
and execute with the same input i get the output as follows:
3 3
5 3
161 3
So, my doubt is why I am not getting:-
3 3
5 5
7 21
3 3 5 161
.printf
distorted your output some how? or you wrote your logic incorrectly? which is it?