Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- int get_problem()
- {
- int select;
- printf("please select your mode:\n"
- "(1)tow-point form\n"
- "(2)point-slope form\n"
- "(3)quite\n");
- scanf("%d",&select);
- return select;
- }
- void get2_pt(double *x,double *y)
- {
- printf("Enter the x-y coordinates of the point separated by a space=> ");
- scanf("%lf%lf",x,y);
- }
- void get2_pt_slope(double *slope)
- {
- printf("Enter the slope=> ");
- scanf("%lf",slope);
- }
- void slope_intcpt_form2_pt(double x[2],double y[2],double *m,double *b)
- {
- *m=(y[1]-y[0])/(x[1]-x[0]);
- *b=y[1]-(*m)*x[1];
- }
- double intcpt_form_pt_slope(double *x,double *y,double *m)
- {
- return (*y-(*m)*(*x));
- }
- void display2_pt(double x[2],double y[2])
- {
- printf("\nTwo-point form");
- printf("\n (%.2lf-%.2lf)",y[1],y[0]);
- printf("\nm = --------------");
- printf("\n (%.2lf-%.2lf)\n\n",x[1],x[0]);
- }
- void display_pt_slope(double x,double y,double m)
- {
- printf("\npoint-slope form");
- printf("\ny - %.2lf = %.2lf ( X - %.2lf )\n\n",y,m,x);
- }
- void display_slope_intcpt(double b,double m)
- {
- printf("\nSlope_intercept form");
- if(b>0)
- printf("\n y = %.2lfX + %.2lf\n\n",m,b);
- else if(b<0)
- printf("\n y = %.2lfX - %.2lf\n\n",m,-1*b);
- else if(b==0)
- printf("\n y = %.2lfX \n\n",m);
- system("pause");
- system("cls");
- }
- int main()
- {
- int loop=0;
- double x[2],y[2],m,b;
- while(loop==0)
- {
- switch(get_problem())
- {
- case 1:
- get2_pt(&x[0],&y[0]);
- get2_pt(&x[1],&y[1]);
- slope_intcpt_form2_pt(x,y,&m,&b);
- display2_pt(x,y);
- display_slope_intcpt(b,m);
- break;
- case 2:
- get2_pt_slope(&m);
- get2_pt(&x[0],&y[0]);
- b=intcpt_form_pt_slope(&x[0],&y[0],&m);
- display_pt_slope(x[0],y[0],m);
- display_slope_intcpt(b,m);
- break;
- case 3:loop=1;
- break;
- default:printf("error\n");
- system("pause");
- system("cls");
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement