Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int min(int a,int b){
- return(a<b)?a:b;
- }
- void floyds(int cost[10][10],int n){
- int i,j,k;
- for(k=0;k<n;k++)
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)
- cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
- }
- int main(){
- int cost[10][10],n,i,j;
- printf("enter the no of vertics\n");
- scanf("%d",&n);
- printf("enter the elements\n");
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)
- scanf("%d",&cost[i][j]);
- floyds(cost,n);
- printf("the answer:");
- for(i=0;i<n;i++){
- for(j=0;j<n;j++){
- printf("%d\t",cost[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
- #include<stdio.h>
- void warshalls(int cost[10][10],int n){
- int i,j,k;
- for(k=0;k<n;k++)
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)
- cost[i][j]=(cost[i][j])||(cost[i][k]&&cost[k][j]);
- }
- int main(){
- int cost[10][10],n,i,j;
- printf("enter the no of vertics\n");
- scanf("%d",&n);
- printf("enter the elements\n");
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)
- scanf("%d",&cost[i][j]);
- warshalls(cost,n);
- printf("the answer:");
- for(i=0;i<n;i++){
- for(j=0;j<n;j++){
- printf("%d\t",cost[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment