Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Given an incidence matrix of an undirected graph, list its
- //edges and give the number of times each edge appears.
- #include <iostream>
- #define max 100
- using namespace std;
- void input(int &n, int &edge, int a[][max])
- {
- cout<<"Input the number of vertices of the graph n= ";
- cin>>n;
- cout<<"Input the number of edges of the graph = ";
- cin>>edge;
- for(int i=1;i<=n;i++)
- for(int j=1;j<=edge;j++)
- {
- cout<<"a["<<i<<"]["<<j<<"] = ";
- cin>>a[i][j];
- }
- }
- void done(int n, int edge, int a[][max])
- { int b1,b2;
- for(int i=1;i<=edge;i++)
- {
- for(int j=1;j<=n;)
- {
- if(a[j][i]!=0)
- {
- b1=j;
- for(int k=j+1;k<=n;k++)
- if(a[k][i]!=0)
- {
- b2=k;
- cout<<"There is "<<a[b1][i]<<" egdes between "<<b1<<" and "<<b2<<endl;
- }
- j++;
- }
- else j++;
- }
- }
- }
- main()
- {
- int n, edge, a[max][max];
- input(n,edge,a);
- done(n,edge,a);
- system("pause");
- }
Add Comment
Please, Sign In to add comment