C Help need....

rosharavinda

Well-known member
  • Dec 28, 2007
    1,588
    166
    63
    Bellanwila
    Mata me program eka karaganna 'C' language eka danna kenek udaw karanwada... Please need you guys help badly...

    Define 10 cities (colombo,kandy,jaffna,matara,Galle, etc) program should assign the code names
    The cities & their co-ordinate are hard coded
    Eg: colombo (2 9) Galle (5 6)

    Generate the 2 co-ordinate points (0,0, to 10,10) (user should input 2 co-ordinate)

    In 15 tries
    If your point is not in map you ignore ,but you loose a try.
    Calculate the total distance you travel in 15 tries

    Total distance= d1+d2+..

    sqrt((x1-x2)^2)+(y1-y2)^2))

    If
    Total distance >= 150km -->you won
    50 <=Total distance < 150km -->Okey
    0 <= Total distance < 50 -->bad try

    Please help me to get this done.... U can get the values any way u like
    Ex: 5,6 or 5 6 for single cordinate
     

    markhaloce

    Member
    Mar 7, 2013
    10,298
    677
    0
    17
    The Real North
    කෝ උඹ ලියපු ටිකත් දාපං.. :dull: :dull:
    ස්ට්‍රක්චර් එකකට ඩබල් දෙකක් දාල ලොකේශන් එක දීපං :dull: :dull:
     

    dmudhitha

    Active member
  • Jan 9, 2009
    658
    49
    28
    distance.png



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

    struct Point {
    int x, y;
    };


    double getDistance(struct Point a, struct Point b)
    {
    double distance;
    distance = sqrt((a.x - b.x) * (a.x - b.x) + (a.y-b.y) *(a.y-b.y));
    return distance;
    }



    int main()
    {
    struct Point a, b;
    printf("Enter coordinate of point a: ");
    scanf("%d %d", &a.x, &a.y);
    printf("Enter coordinate of point b: ");
    scanf("%d %d", &b.x, &b.y);
    printf("Distance between a and b: %lf\n", getDistance(a, b));


    return 0;
    }

    output.PNG



    Source