Skip to content

Instantly share code, notes, and snippets.

@somratcste
Created September 30, 2013 21:22
Show Gist options
  • Save somratcste/6770478 to your computer and use it in GitHub Desktop.
Save somratcste/6770478 to your computer and use it in GitHub Desktop.
Two points such as (x1,y1) and (x2,y2) for how we can find the straight line equation such type of program are described here.
#include <stdio.h>
int main()
{
int p[2],q[2],x,i,j,k;
float m,y;
printf("Enter your two points : \n");
for(i=1;i<=2;i++)
{
printf("x[%d] : ",i);
scanf("%d", &p[i]);
printf("y[%d] : ",i);
scanf("%d", &q[i]);
}
printf("Your putting two value are : \n\n");
for(i=1;i<=2;i++)
printf("x[%d] : %d \t y[%d] : %d\n",i,p[i],i,q[i]);
j=q[2]-q[1];
k=p[2]-p[1];
m=j/k;
y=q[1]-m*p[1];
if(j==k)
{
j=k=1;
printf("\n\nYour equation are : \n");
printf("\t\ty=%dx+%.1f\n\n",j,y);
}
else
{
printf("\n\nYour equation are : \n");
printf("\t\ty=%d/%dx+%.1f\n\n",j,k,y);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment