Thursday, April 30, 2009

sol tut7 ecp1026

#include
#define NUMPLACE 3
#define NOP -1.0

char places[NUMPLACE]={'A','B','C'};

float roads[NUMPLACE][NUMPLACE]={
{0.0,3.5,NOP},
{3.2,0.0,2.8},
{3.1,NOP,0.0},
};

int main(void){
int from;
int to;
char origin, dest;

printf("From>>");
scanf("%c",&origin);

for(from=0;from>");
scanf("%c",&dest);

for(to=0;to
if(places[to]==dest)break;

printf("From %c to %c ", places[from],places[to]);
if(roads[from][to]!=NOP)
printf("it is %2.1f km\n",roads[from][to]);
else
printf("no direct road.\n");

return(0);
}

No comments: