Prime #### Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime #### Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

# Accenture Coding Question 14 ## Coding Question 14

Instructions: You are required to write the code. You can click on compile & run anytime to check the compilation/ execution status of the program. The submitted code should be logically/syntactically correct and pass all the test cases.

Ques: The program is supposed to calculate the distance between three points.

For,

x1 = 1,  y1 = 1
x2 = 2 , y2 = 4
x3 = 3,  y3 = 6

Distance is calculated as : sqrt(x2-x1)2 + (y2-y1)2

`#include <stdio.h>#include <math.h>int isDistance(float *pt1, float *pt2, float *pt3){float a, b, c;a = sqrt(((pt2-pt1)*(pt2-pt1))+((pt2-pt1)*(pt2-pt1)));printf(“%f”,a);b = sqrt(((pt3-pt2)*(pt3-pt2))+((pt3-pt2)*(pt3-pt2)));printf(“%f”,b);c = sqrt(((pt3-pt1)*(pt3-pt1))+((pt3-pt1)*(pt3-pt1)));printf(“%f”,c);}int main(){ int t;float p1, p2, p3;printf("enter x1 and y1 : ");scanf("%f%f",&p1,&p1);printf("enter x2 and y2 : ");scanf("%f%f",&p2,&p2);printf("enter x3 and y3 : ");scanf("%f%f",&p3,&p3);t = isDistance(&p1, &p2, &p3);printf("%d",t);return 0;}`
```import math

x1, y1 = 1, 1
x2, y2 = 2, 4
x3, y3 = 3, 6

first_diff = math.sqrt(math.pow(x2-x1, 2) + math.pow(y2-y1, 2))
second_diff = math.sqrt(math.pow(x3-x2, 2) + math.pow(y3-y2, 2))
third_diff = math.sqrt(math.pow(x3-x1, 2) + math.pow(y3-y1, 2))

print(round(first_diff,2), round(second_diff,2), round(third_diff,2))```