Vikhyath_11

p5

Jul 26th, 2024
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include<stdio.h>
  2. int min(int a,int b){
  3. return(a<b)?a:b;
  4. }
  5. void floyds(int cost[10][10],int n){
  6. int i,j,k;
  7. for(k=0;k<n;k++)
  8. for(i=0;i<n;i++)
  9. for(j=0;j<n;j++)
  10. cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
  11. }
  12. int main(){
  13. int cost[10][10],n,i,j;
  14. printf("enter the no of vertics\n");
  15. scanf("%d",&n);
  16. printf("enter the elements\n");
  17. for(i=0;i<n;i++)
  18. for(j=0;j<n;j++)
  19. scanf("%d",&cost[i][j]);
  20. floyds(cost,n);
  21. printf("the answer:");
  22. for(i=0;i<n;i++){
  23. for(j=0;j<n;j++){
  24. printf("%d\t",cost[i][j]);
  25. }
  26. printf("\n");
  27. }
  28.  
  29. return 0;
  30. }
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. #include<stdio.h>
  39. void warshalls(int cost[10][10],int n){
  40. int i,j,k;
  41. for(k=0;k<n;k++)
  42. for(i=0;i<n;i++)
  43. for(j=0;j<n;j++)
  44. cost[i][j]=(cost[i][j])||(cost[i][k]&&cost[k][j]);
  45. }
  46. int main(){
  47. int cost[10][10],n,i,j;
  48. printf("enter the no of vertics\n");
  49. scanf("%d",&n);
  50. printf("enter the elements\n");
  51. for(i=0;i<n;i++)
  52. for(j=0;j<n;j++)
  53. scanf("%d",&cost[i][j]);
  54. warshalls(cost,n);
  55. printf("the answer:");
  56. for(i=0;i<n;i++){
  57. for(j=0;j<n;j++){
  58. printf("%d\t",cost[i][j]);
  59. }
  60. printf("\n");
  61. }
  62.  
  63. return 0;
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment