-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinear.c
68 lines (67 loc) · 921 Bytes
/
linear.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<stdio.h>
int* exgcd(int a,int b)
{
int r,q,s,t,s1=1,s2=0,t1=0,t2=1;
int arr[2];
while(b>0)
{
q=a/b;
r=a%b;
a=b;
b=r;
if(r==0)
break;
s=s1-(q*s2);
s1=s2;
s2=s;
t=t1-(q*t2);
t1=t2;
t2=t;
}
arr[0]=s;
arr[1]=t;
return arr;
}
void main()
{
int x,y,c,s,t;
printf("enter x coefficient ");
scanf("%d",&x);
printf("enter y coefficient");
scanf("%d",&y);
printf("enter value of constant");
scanf("%d",&c);
int gc=gcd(x,y);
printf("gcd is %d",gc);
s=x/gc;
t=y/gc;
if(gc==1)
printf("no solution exist");
if(gc>1)
{
int *d=exgcd(s,t);
int x1=(c/gc)*d[0];
printf("value of particularx= %d \n ",x1);
int y1=(c/gc)*d[1];
printf("value of particulary= %d \n ",y1);
int px,py,i;
for(i=1;i<=5;i++)
{
px=x1+i*(y/gc);
printf("general= %d \n",px);
py=y1+i*(x/gc);
printf("general= %d \n",py);
}
}
}
int gcd(int a,int b)
{
int r;
while(b>0)
{
r=a%b;
a=b;
b=r;
}
return a;
}