Advertisement
lily09290110

求方程(副程式練習版)

Jan 6th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. int get_problem()
  5. {
  6. int select;
  7. printf("please select your mode:\n"
  8. "(1)tow-point form\n"
  9. "(2)point-slope form\n"
  10. "(3)quite\n");
  11. scanf("%d",&select);
  12. return select;
  13. }
  14. void get2_pt(double *x,double *y)
  15. {
  16. printf("Enter the x-y coordinates of the point separated by a space=> ");
  17. scanf("%lf%lf",x,y);
  18. }
  19. void get2_pt_slope(double *slope)
  20. {
  21. printf("Enter the slope=> ");
  22. scanf("%lf",slope);
  23. }
  24. void slope_intcpt_form2_pt(double x[2],double y[2],double *m,double *b)
  25. {
  26. *m=(y[1]-y[0])/(x[1]-x[0]);
  27. *b=y[1]-(*m)*x[1];
  28. }
  29. double intcpt_form_pt_slope(double *x,double *y,double *m)
  30. {
  31. return (*y-(*m)*(*x));
  32. }
  33. void display2_pt(double x[2],double y[2])
  34. {
  35. printf("\nTwo-point form");
  36. printf("\n (%.2lf-%.2lf)",y[1],y[0]);
  37. printf("\nm = --------------");
  38. printf("\n (%.2lf-%.2lf)\n\n",x[1],x[0]);
  39. }
  40. void display_pt_slope(double x,double y,double m)
  41. {
  42. printf("\npoint-slope form");
  43. printf("\ny - %.2lf = %.2lf ( X - %.2lf )\n\n",y,m,x);
  44. }
  45. void display_slope_intcpt(double b,double m)
  46. {
  47. printf("\nSlope_intercept form");
  48. if(b>0)
  49. printf("\n y = %.2lfX + %.2lf\n\n",m,b);
  50. else if(b<0)
  51. printf("\n y = %.2lfX - %.2lf\n\n",m,-1*b);
  52. else if(b==0)
  53. printf("\n y = %.2lfX \n\n",m);
  54. system("pause");
  55. system("cls");
  56. }
  57. int main()
  58. {
  59. int loop=0;
  60. double x[2],y[2],m,b;
  61. while(loop==0)
  62. {
  63.  
  64. switch(get_problem())
  65. {
  66. case 1:
  67. get2_pt(&x[0],&y[0]);
  68. get2_pt(&x[1],&y[1]);
  69. slope_intcpt_form2_pt(x,y,&m,&b);
  70. display2_pt(x,y);
  71. display_slope_intcpt(b,m);
  72. break;
  73. case 2:
  74. get2_pt_slope(&m);
  75. get2_pt(&x[0],&y[0]);
  76. b=intcpt_form_pt_slope(&x[0],&y[0],&m);
  77. display_pt_slope(x[0],y[0],m);
  78. display_slope_intcpt(b,m);
  79. break;
  80. case 3:loop=1;
  81. break;
  82. default:printf("error\n");
  83. system("pause");
  84. system("cls");
  85. break;
  86. }
  87. }
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement