Answer to Question #277916 in C for Sowjanya

Question #277916

Find latitude and longitude of 20 countries with a population greater than or equal to the population limit given below. Use the country details from this dataset.

Your task is to find the sum of the length of all lines (in kms) that can be drawn between co-ordinates of these countries.

  • Assume radius of earth: 6371 km
  • Round length of each line and final result to 2 decimal points
  • If co-ordinates are missing for any country use 0.000 N 0.000 E

Population limit: 300

Note: Population limit will change at random intervals. So please make sure answer is computed for the correct population limit before submitting.



1
Expert's answer
2021-12-10T07:17:19-0500
#include <stdio.h>
#include <cmath.h>

struct coordinate {
  double latutude, longitude
}

typedef struct coordinate coor_t

double calc_dist(coor_t coor1, coor_t coor2)
{
  double latitude1 = coor1.latitude * PI / 180;
  double longitude1 = coor1.longitude  * PI / 180;
  double latitude2 = coor2.latitude * PI / 180;
  double longitude2 = coor2.longitude * PI / 180;
  
  double d = 2 * 6371 * asin(sqrt(sin(pow((latitude2 - latitude1) / 2, 2)) +
        cos(latitude1) * cos(latitude2) * sin(pow((longitude2 - longitude1) / 2, 2))));
  return round(d, 2);
}

const char *file = "countries.csv";
const int limit = 300;

int main() {
  // need parse file and cacl total dist using calc_dist function
  return 0;
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS