3
#include <stdio.h>
#include <math.h>

int main() {
    float g1, g2, c1, c2, dismul, cadd, csub, dis;

    printf("Enter the latitudes of the places (L1 and L2): ");
    scanf("%f %f", &c1 ,&c2);
    printf("Enter the longitudes of the places (G1 and G2): ");
    scanf("%f %f ", &g1, &g2);
    cadd = cos(c1 + c2);
    csub = cos(g2-g1);
    dismul = cadd * csub;
    dis = 3963 * acos(dismul);
    printf("The distance between the places is:%f\n", dis);
    return 0;
}

I wrote this code to give distance between two points but when I run it, it does not give the last printf until I type any letter and press enter.

chqrlie
  • 131,814
  • 10
  • 121
  • 189
Meet Singh
  • 39
  • 6

1 Answers1

5

as already pointed out in comments, on line 9 of your code ( scanf("%f %f ",&g1,&g2);)

There is an extra space after the second "%f", so scanf() is expecting to read a whitespace after a floating point character.

replace it with

scanf("%f %f",&g1,&g2);

to fix it.

Arsenic
  • 727
  • 1
  • 8
  • 22