luc061.c (1191B)
1 /* The area of a triangle can be computed by the sine law. Given 6 triangular pieces of land (a, b, angle), find their area and determine which is largest. 2 */ 3 4 /* Let Us C, Chap- 13 (Arrays), Qn No.: B(g) */ 5 6 /* This file is auto-generated by a bot. */ 7 /* This code is not compiled; it is for reference only. */ 8 9 10 #include <stdio.h> 11 #include <math.h> 12 #include <stdlib.h> 13 14 int main() 15 { 16 // Data arrays 17 double a[] = {137.4, 155.2, 149.3, 160.0, 155.6, 149.7}; 18 double b[] = {80.9, 92.62, 97.93, 100.25, 68.95, 120.0}; 19 double angle[] = {0.78, 0.89, 1.35, 9.00, 1.25, 1.75}; // Assuming radians based on values < 2.0. 9.00 is treated as literal. 20 21 double area, max_area = 0.0; 22 int i, max_index = -1; 23 24 printf("Plot No.\tArea\n"); 25 printf("------------------------\n"); 26 27 for (i = 0; i < 6; i++) 28 { 29 // Area = 1/2 * a * b * sin(angle) 30 area = 0.5 * a[i] * b[i] * sin(angle[i]); 31 32 printf("%d\t\t%.2f\n", i + 1, area); 33 34 if (area > max_area) 35 { 36 max_area = area; 37 max_index = i + 1; 38 } 39 } 40 41 printf("\nLargest Plot is No. %d with Area: %.2f\n", max_index, max_area); 42 43 return 0; 44 }