-8

iam amateur at programming. I am trying to show each steps of this algorithm but i want to present 1000 as INF on each D matrix.

need more lines to submit need more lines to submit need more lines to submit need more lines to submit need more lines to submit need more lines to submit need more lines to submit need more lines to submit need more lines to submit need more lines to submit need more lines to submit

#include <iostream>
#include <limits>
#define INF 1000

using namespace std;

/* my example matrix is 
0  3  inf  7
8  0   2  inf
5 inf  0   1
2 inf inf  0

i want to write that each D matrix show 1000 as INF
*/

void FloydWarshall(int **dist, int V){

int i,j,k;

for(k = 0; k < V; k++){
cout<<"D"<<k<<" matrix is: "<<endl;

for(i = 0; i < V; i++){

    for(j = 0; j < V; j++){
        cout<<dist[i][j]<<"     ";
        if(dist[i][k] != INF && dist[j][k] != INF && dist[i][j] > (dist[i][k] + dist[k][j]))
                dist[i][j] = dist[i][k]+dist[k][j];  
                          } 
                cout<<"  "<<endl;
                      }
                cout<<"  "<<endl;
                  }     


for(i = 0; i < V; i++){ 
    for(j = 0; j < V; j++){
        cout<<" "<<endl;
        cout<<"Shortest path between "<<i<<" and "<<j<<" is : "<<endl;
        if(dist[i][j]==INF)
                cout<<"INF"<<endl;
        else
                cout<<dist[i][j]<<endl;
                          } 
                      }    

   }

int main(){


int i,j,n;
int **dist;
int *cost;

cout<<"Please, enter the number of vertices: "<<endl;
cin>>n;

dist = new int*[n];

for(i = 0;i < n; i++){
dist[i] = new int[n];
}

cout<<"Please, enter the adjacency matrix: "<<endl;
cout<<"Do not forget "<<INF<<" if there is no connection between two vertices"<<endl;
for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
        cin>>dist[i][j];
        if (dist[i][j] == 0 && i != j){
            dist[i][j] = INF;
 }
 }
 }
cout<<"  "<<endl;

FloydWarshall(dist,n);
cout<<" "<<endl;
cout<<"     The Distance Matrix is:     "<<endl;
  for(i=0;i<n;i++)
 {
  for(j=0;j<n;j++)
 {
      cout<<dist[i][j]<<"     ";
 }
cout<<"\n";
 }
return 0;
 }
user4581301
  • 33,082
  • 7
  • 33
  • 54
  • 3
    Need more lines to explain. – Yunnosch Jun 21 '18 at 20:50
  • 7
    When the site tells you that you need more lines to submit a question, it means that you need more *meaningful* lines to submit. Please don't try to game the system. – Sergey Kalinichenko Jun 21 '18 at 20:50
  • 1
    Before selecting a tag you are not familiar with, give the tag wiki a read to make sure your tag applies. C and task do not apply to this question. – user4581301 Jun 21 '18 at 20:51
  • 1
    Sane and regular indentation helps prevent bugs by making bugs easier to spot. – user4581301 Jun 21 '18 at 20:53
  • 5
    "need more lines to submit need more lines to submit need more lines to submit need more lines to submit need more lines" - you are not doing yourself any favours with that. – Jesper Juhl Jun 21 '18 at 20:56
  • you people do not realize i almost completed the problem and you complain that i need to explain further.. what should i do? explain how i wrote this code from start? i just need 1 or 2 lines to solve this problem – Kamran Mammadli Jun 21 '18 at 21:50
  • You will most likely need `if` statements to detect 1000 and replace it with "INF" when you print. – user4581301 Jun 21 '18 at 22:03

1 Answers1

0

if (variable >= 1000) { printf("INF"); }

I chose a random variable name, but this logic should do what you want.

MPops
  • 355
  • 3
  • 8
  • thank you for post, your answer gave me an idea what to do so i used and it worked:) if(dist[i][j]==INF) cout<<"INF\t"; else cout< – Kamran Mammadli Jun 21 '18 at 22:29