Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

yout References Mailings Review View x, x\' : A·-A. | 1. : ·m . Normal No Spac H

ID: 3724584 • Letter: Y

Question

yout References Mailings Review View x, x' : A·-A. | 1. : ·m . Normal No Spac Heading 1 Heading 2 Title Font Paragraph Styles 2.(7) Two points in a plane (a-y coordinate system)are specified using the coordinates (x1, y1) and (x2, y2). Write a program that gets the points from the user and (a) calculates the distance between them; (b) outputs length of the line segment to the screen. (9) Write a program to calculate the area of a triangle given the lengths of its three sides a, b, c, using Heron's formula: 3. A-sqrt s(s-a)(s-b)s- c)) where s- (a +bc)2, the semi-perimeter Get the lengths of the sides from the user. Calculate the area of the triangle and output the area to the screen. Under certain circumstances, the lengths of three line segments do not form a triangle (i, e., the sum] of any two sides must be greater than the third-a + b > c, a + c > b and b+c>a). Revise the program to check that the line segments will form a triangle and if not, inform the user and ask for different lengths.

Explanation / Answer

//Question 1 solution in java

import java.util.*;
public class MyClass {
public static void main(String args[]) {
double x1,y1,x2,y2;
Scanner sc =new Scanner(System.in);
System.out.println("enter value of x1:");
x1=sc.nextDouble();
System.out.println("enter value of y1:");
y1=sc.nextDouble();
System.out.println("enter value of x2:");
x2=sc.nextDouble();
System.out.println("enter value of y2:");
y2=sc.nextDouble();
//calculate the distance
double distance=Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
//output the distance
System.out.println("distance between the points is:"+distance);
}
}

//question 1 in c

#include <stdio.h>
#include<math.h>
int main()
{
  
float x1,y1,x2,y2,distance;
printf("enter value of x1:");
scanf("%f",&x1);
printf("enter value of y1:");
scanf("%f",&y1);
printf("enter value of x2:");
scanf("%f",&x2);
printf("enter value of y2:");
scanf("%f",&y2);
//calculate the distance
distance=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
//output the distance
printf("distance between the points is %f:",distance);

return 0;
}

//question 2 in java

import java.util.*;
public class MyClass {
public static void main(String args[]) {
double a=0,b=0,c=0,s=0,area=0;
int flag=-1;
while(flag==-1)
{
Scanner sc =new Scanner(System.in);
System.out.println("enter value of side a");
a=sc.nextDouble();
System.out.println("enter value of side b");
b=sc.nextDouble();
System.out.println("enter value of side c");
c=sc.nextDouble();
if((c<a+b) && (a<b+c) && (b<a+c))
flag=1;//triangle is possible
else
{System.out.println("triangle is not possible,");
System.out.println("please enter correct sides.");
}
}
s=(a+b+c)/2;

//calculate the area
area=Math.sqrt(s*(s-a)*(s-b)*(s-c));
//output the distance
System.out.println("area of triangle is:"+area);
}
}

//question 2 in c

#include <stdio.h>
#include<math.h>
int main()
{
float a=0,b=0,c=0,s=0,area=0;
int flag=-1;
while(flag==-1)
{

printf("enter value of side a:");
scanf("%f",&a);
printf("enter value of side b:");
scanf("%f",&b);
printf("enter value of side c:");
scanf("%f",&c);
if((c<a+b) && (a<b+c) && (b<a+c))
flag=1;//triangle is possible
else
{printf("triangle is not possible,");
printf("please enter correct sides.");
}
}
s=(a+b+c)/2;

//calculate the area
area=sqrt(s*(s-a)*(s-b)*(s-c));
//output the distance
printf("area of triangle is: %f",area);
return 0;
}