Simple Computational C Problems - Basic C Programs
Write a 'C' program to calculate slope and midpoint of a line.
Let x1, y1 and x2, y2 are the coordinates of the extremities of the line.
The slope of this line is
Slope = [y2‒yl] / [x2‒x1]
For mid point of the line is
x co‒ordinate is x = [x1+x2] / 2
y co‒ordinate is y = [y2+yl] / 2
for this problem x1,y1, x2,y2 are the inputs, slope is output.
/* Program to calculates slope and midpoint of a line */
#include<stdio.h>
main()
{
/* Local definition */
float x,y,x1,x2, yl, y2, slope;
*Statements */
printf("Enter the First Point xl,yl...");
scanf("%f%f", &x1, &yl);
printf("Enter the Second Point x2,y2..........");
scanf("%f%f", &x2, &y2);
slope = (y2‒y1)/(x2‒x1); /* calculates the slope value */
x=(x1+x2)/2.0; /* calculates x value */
y=(y1+y2)/2.0; /* calculates y value */
printf("Slope is.....%f\n", slope);
printf("Mid Point is.....%f, %f", x,y);
} /* main */
OUTPUT
Enter the First Point x1,y1... 10 20
Enter the Second Point x2,y2... 30 40
Slope is.....1.000000
Mid Point is.....20.000000, 30.000000
EXPLANATION: In the program the variables x1, y1 and x2, y2 are read through the keyboard. The variable slope holds the result of (y2‒y1)/(x2‒x1) then x is calculated by (x1+x2)/2.0 and y value is calculated by (y1+y2)/2.0. Finally the slope value is printed and midpoint is printed from the variables x and y.
Computer Programming C Laboratory: Basic C Programs : Tag: C Programming : - Write a C program to calculate slope and midpoint of a line
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
English Essentials I
EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
தமிழர் மரபு - Heritage of Tamils
UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Calculus
MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I
PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Chemistry I
CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Makerspace
ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming C
CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming Python
CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Fundamentals of Electrical and Electronics Engineering
EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Mechanical Engineering
ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Civil Engineering
CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing
CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I Laboratory
PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Applied Chemistry I Laboratory
CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming Python Laboratory
CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Engineering Drawing
ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electronics and Electrical Engineering
EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing - Laboratory
CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation