Solved

matrix multiplication

Posted on 1998-12-02
4
249 Views
Last Modified: 2010-04-02
I don't know why my program doesn't work or how to fix it so it would work.

my program must calculate the number of connections of a given length which connect two nodes of a diagraph.  My program read the original adjacency matrix from a file, which is this:
4
0 1 1 0
1 1 1 0
1 0 0 1
0 0 0 0
The program prompts the user for the desired connection length and the names of two nodes.
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <stdlib.h>
int xxx;

void count(int table1[][5], int table2[][5], int table3[][5], int cnt){
      int temp=0;
      int i;
      int j;
      int k;
      
      cout<<"in count cnt="<<cnt<<endl;
      for (i=0; i<=3; i=i+1){

            for(j=0; j<=3; j=j+1){
                  for (k=0; k<=cnt; k=k+1)
                        table3[i][j]=table3[i][j]+table1[i][k]*table2[k][j];
      cout<<table3[i][j]<<endl;;
            }
      }
      
}



void multiple(int table[][5], int cnt, int size){
      int i;
      
      int j;
      int k;
      int tempk1[5][5];
      int tempk2[5][5];
      cout<<"in multi cnt="<<cnt<<endl;
      cin>>xxx;

      for (i=0; i<cnt; i=i+1){
            for(j=0; j<cnt; j+j+1){
            tempk1[i][j]=table[i][j];
            cout<<"tempk1["<<i<<"]["<<j<<"]="<<tempk2[i][j]<<endl;
            cout<<"hello";
            cin>>xxx;

            }
      }
      

      for (i=1; i<size; i=i+1){
            
            for (j=1; j<size; j=j+1){
                  count(table, tempk1, tempk2, cnt);

                  for (i=1; i<cnt; i=i+1){
                        cout<<"i'm in the first loop before tempk1";
                        for (j=1; j<cnt; j=j+1){
                        tempk2[i][j]=tempk1[i][j];
                        cin>>xxx;

            }
      
      }
            }
}
      }
void main()
{
      int i, j;
      int node1;
      int node2;
      int length;
      int cnt;
      int size;
      int table[5][5];
      int table3[5][5];
      fstream outFile;


      outFile.open("c:/mydocuments/test1.txt",ios::in);
            cout<<"enter length number";
            cin>>length;
            cout<<"enter node from";
            cin>>node1;
            cout<<"enter node to";
            cin>>node2;
            cnt=length;
            outFile>>size;
            for (i=0; i<size; i=i+1){
                  for (j=0; j<size; j=j+1){
            outFile>>table[i][j];
            for (i=0; i<size; i=i+1){
                  for (j=0; j<size; j=j+1){
                        cout<<"table="<<table[i][j];
            
                  
      
            multiple(table, cnt, size);
      
      cout<<table[node1][node2];
                  }
      }
                  }

      }
      outFile.close();
}
      
0
Comment
Question by:tulchirx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1179149
What problems are you having?
0
 

Accepted Solution

by:
andromeda120198 earned 120 total points
ID: 1179150
You have k and  table3 as unrefernced local variable.modify your program by referring to these local variables.Let me know what else problems you have ?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1179151
>> modify your program by referring to these local variables
ROTFLMAO!!!
0
 

Author Comment

by:tulchirx
ID: 1179152
thanks anyway, but my program works now alright
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question