This blog is under construction

Tuesday, 9 July 2013

C program to find slope

Write a C program to find slope.


  #include <stdio.h>

  int main() {
        int x1, y1, x2, y2;
        float slope;

        /* Get the input for first point from the user */
        printf("Enter the value for 1st point(x1, y1):");
        scanf("%d%d", &x1, &y1);

        /* Get the input for second point from the user */
        printf("Enter the value of 2nd point(x2, y2):");
        scanf("%d%d", &x2, &y2);

        /* calculate slope */
        slope = ((1.0)* (y2 - y1)) / (x2 - x1);

        /* print the calculated slope value */
        printf("Slope = %.2f\n", slope);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/cpgms/$ ./a.out
  Enter the value for 1st point(x1, y1):3 -2
  Enter the value of 2nd point(x2, y2):9 2
  Slope = 0.67




See Also:

1 comment: