LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-14-2005, 10:10 AM   #1
jacques83
Member
 
Registered: Nov 2005
Posts: 34

Rep: Reputation: 15
trying to find the maximum in a 2 d matrice for graph coloring


hello, i am trying to code a converter placement problem for a graph.i am getting stuck on printing the max nodal deg for my graph. my code is as follows...

max=0;
for(i=0;i<2;i++)
for(j=0;j<2;j++)
{
{
if(node_deg[i][j]<node_deg[i][j+1])
max=node_deg[i][j+1];
}
printf("the maximum nodal degree is%d ",max);
}

i feel that while printing the final degree, i am printing the value outside my domain space.any suggestions????


thanks
 
Old 11-14-2005, 10:19 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
does it work with the braces in these positions?
whats the max size of the second index? is it 2?
 
Old 11-14-2005, 10:41 AM   #3
jacques83
Member
 
Registered: Nov 2005
Posts: 34

Original Poster
Rep: Reputation: 15
i thnk i got the code..tis as follows...thanks anyways

#include<stdio.h>
#include<conio.h>

int main(void)
{
int node_deg[4][4];
int node_link[4][4];
int i,j,max,max_node;
printf("enter the nodal degrees for each node");
for(i=0;i<4;i++)
for(j=0;j<4;j++)
scanf("%d",&node_deg[i][j]);
printf("the nodal degrees you entered\t");
for(i=0;i<4;i++)
{
printf("\n");
printf("Node%d:\t",i);
for(j=0;j<4;j++)
{
printf("%d\t",node_deg[i][j]);

}
}
printf("\nenter the nodal links for each node");
for(i=0;i<4;i++)
for(j=0;j<4;j++)
scanf("%d",&node_link[i][j]);
printf("the nodal links you entered\t");
for(i=0;i<4;i++)
{
printf("\n");
printf("Node%d:\t",i);
for(j=0;j<4;j++)
{
printf("%d\t",node_link[i][j]);

}
}
//printf("the maximum nodal degree is%d ",max);
max=0;
max_node=0;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(max<node_deg[i][j])
{
max=node_deg[i][j];
max_node=i;
}
}
//printf("the maximum nodal degree is%d ",max);
}
printf("\nthe node with the highest degree is::%d having degree::%d",max_node,max);
//printf("the maximum nodal degree is::%d ",max);
getch();
return 0;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[LaTeX] Coloring environments solarize Linux - Software 3 09-04-2005 03:54 PM
vi terminal coloring issue feetyouwell Linux - Software 1 01-05-2005 03:58 PM
Coloring real-time logs on tty d1s4st3r Linux - Newbie 4 09-03-2004 05:40 PM
Aterm background coloring sellsw1711 Linux - Newbie 16 03-19-2004 01:15 AM
turning off syntax coloring in vim, permanently davalos Linux - Newbie 5 08-18-2003 09:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration