#include<stdio.h>
#include<conio.h>
void main()
{
int ab,bc,ch,bd,de,df,ce,eg,gh,af,fg;
int sum[10],max[10],i,j;
clrscr();
printf(" B ________________C \n");
printf(" /\\ /\\ \n");
printf(" / \\ / \\ \n");
printf(" / \\ / \\ \n");
printf(" A D---------E H \n");
printf(" \\ / \\ / \n");
printf(" \\ / \\ / \n");
printf(" \\/ \\/ \n");
printf(" F----------------G \n");
printf("ENTER VALUE OF:-");
printf("\nAB:-");
scanf("%d",&ab);
printf("\nBC:-");
scanf("%d",&bc);
printf("\nCH:-");
scanf("%d",&ch);
printf("\nBD:-");
scanf("%d",&bd);
printf("\nDE:-");
scanf("%d",&de);
printf("\nDF:-");
scanf("%d",&df);
printf("\nCE:-");
scanf("%d",&ce);
printf("\nEG:-");
scanf("%d",&eg);
printf("\nGH:-");
scanf("%d",&gh);
printf("\nAF:-");
scanf("%d",&af);
printf("\nFG:-");
scanf("%d",&fg);
printf(" B________________C \n");
printf(" %d /\\ %d /\\ \n",ab,bc);
printf(" / \\%d %d / \\ %d \n",bd,ce,ch);
printf(" / \\ / \\ \n");
printf(" A D---------E H \n" );
printf(" \\ / %d \\ / \n",de);
printf(" %d \\ /%d %d\\ / %d \n",af,df,eg,gh);
printf(" \\/ %d \\/ \n",fg);
printf(" F----------------G \n");
sum[0]=ab+bc+ch;
sum[1]=ab+bd+de+ce+ch;
sum[2]=ab+bd+de+eg+gh;
sum[3]=ab+bd+df+fg+eg+ce+ch;
sum[4]=ab+bd+df+fg+gh;
sum[5]=af+fg+gh;
sum[6]=af+df+de+eg+gh;
sum[7]=af+df+de+ce+ch;
sum[8]=af+df+bd+bc+ch;
sum[9]=af+df+bd+bc+ce+eg+gh;
printf("\npath1:-A-B-C-H->%d",sum[0]);
printf("\npath2:-A-B-D-E-C-H->%d",sum[1]);
printf("\npath3:-A-B-D-E-G-H->%d",sum[2]);
printf("\npath4:-A-B-D-F-G-E-C-H->%d",sum[3]);
printf("\npath5:-A-B-D-F-G-H->%d",sum[4]);
printf("\npath6:-A-F-G-H->%d",sum[5]);
printf("\npath7:-A-F-D-E-G-H->%d",sum[6]);
printf("\npath8:-A-F-D-E-C-H->%d",sum[7]);
printf("\npath9:-A-F-D-B--C-H->%d",sum[8]);
printf("\npath10:-A-F-D-B-C-E-G-H->%d",sum[9]);
for(i=0;i<10;i++)
max[i]=sum[i];
for(i=0;i<10;i++)
{
for(j=0;j<9;j++)
{
if(sum[j]>sum[j+1])
{
sum[j]=sum[j]+sum[j+1];
sum[j+1]=sum[j]-sum[j+1];
sum[j]=sum[j]-sum[j+1];
}
}
}
printf("\nSHORTEST PATH:-");
if(sum[0]==max[0])
printf("\npath1:-A-B-C-H->%d",sum[0]);
else if(sum[0]==max[1])
printf("\npath2:-a-b-d-e-c-h->%d",sum[0]);
else if(sum[0]==max[2])
printf("\npath3:-a-b-d-e-g-h->%d",sum[0]);
else if(sum[0]==max[3])
printf("\npath4:-a-b-d-f-g-e-c-h->%d",sum[0]);
else if(sum[0]==max[4])
printf("\npath5:-a-b-d-f-g-h->%d",sum[0]);
else if(sum[0]==max[5])
printf("\npath6:-a-f-g-h->%d",sum[0]);
else if(sum[0]==max[6])
printf("\npath7:-a-f-d-e-g-h->%d",sum[0]);
else if(sum[0]==max[7])
printf("\npath8:-a-f-d-e-c-h->%d",sum[0]);
else if(sum[0]==max[8])
printf("\npath9:-a-f-d-b--c-h->%d",sum[0]);
else if(sum[0]==max[9])
printf("\npath10:-a-f-d-b-c-e-g-h->%d",sum[0]);
getch();
}
No comments:
Post a Comment