80 likes | 109 Views
Programming Project #1 Numerical Computations. CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language , 2 nd edition, by Kernighan and Ritchie and from C: How to Program , 5 th and 6 th editions, by Deitel and Deitel). Purpose.
E N D
Programming Project #1Numerical Computations CS-2301, System Programmingfor Non-Majors (Slides include materials from The C Programming Language, 2nd edition, by Kernighan and Ritchie and from C: How to Program, 5th and 6th editions, by Deitel and Deitel) Circumference and Area of a Triangle
Purpose • Write a simple C program that • Reads some data from the keyboard • Computes a simple engineering or scientific formula • Prints the answer on the output screen • The formula is supplied:– • Circumference and area of a triangle, given its three vertices Circumference and Area of a Triangle
Your Program • Develop on CCC Linux system • Called triangle.c • Prompt user for inputs:– • Use scanf() • See §§B1.2-B1.3 of K & R • Repeat three times total • x- and y-coordinates each of points A, B, and C • Calculate and print • Lengths of the three sides of the triangle • Circumference of the triangle • Area of the triangle • Use printf() Circumference and Area of a Triangle
Formulas • See handout • Length of side between A and B • Where point A is given by xA, yA • Where point B is given by xB, yB • Area is given by • Where s = ½ (lAB + lBC + lCA). Circumference and Area of a Triangle
Sample Input Enter the x-coordinate of point A:- 1.05 Enter the y-coordinate of point A:- 2 Enter the x-coordinate of point B:- 1.115e+2 Enter the y-coordinate of point B:- 21.1 Enter the x-coordinate of point C:- -25 Enter the y-coordinate of point C:- -3.14159265358979323846 Circumference and Area of a Triangle
Sample Output Length of AB is 112.089 Length of BC is 138.636 Length of CA is 26.553 Circumference is 277.278 Area is 35.181 Circumference and Area of a Triangle
Things You Need to Know • sqrt(expression); • printf("string", arg1, arg2, …); • scanf("string", &arg1, &arg2, …); Circumference and Area of a Triangle
Questions? Circumference and Area of a Triangle