/*PROGRAM TO SIMULATE ROUTING USING FLOODING*/
#include<stdio.h>
#include<conio.h>
int a[30][30],i,j,k=0,l=0,b[20],cnt=0,n,seq[30],ch;
char c1='x';
main()
{
clrscr();
b[1]=1;
printf("Enter no.of nodes:");
scanf("%d",&n);
printf("\nConstruct graph");
for(i=1;i<=n;i++)
{
printf("\nEnter edges for %d:",i);
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
}
printf("\n\t\tMENU");
printf("\n\t\t*********************");
printf("\n\t\t1. FLODDING WITH OUT SOLUTION");
printf("\n\t\t1. FLODDING WITH SOLUTION");
printf("\n\t\t**********************");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: for(i=1;i<=n;i++)
{
l=0;
for(j=1;j<=n;j++)
if(a[i][j]!=0)
l++;
if(i<j)
cnt++;
b[i+1]=l*cnt;
}
flood();
break;
case 2: for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(a[i][j]!=0 && i<j)
if(seq[j]!=1)
{
printf("\n%d-->%d",i,j);
printf("%c",c1);
seq[j]=1;
}
break;
default: exit(0);
}
getch();
}
flood()
{
printf("\n RECEIVED PACKETS ARE");
for(i=1;i<=n;i++)
{
for(j=2;j<=n;j++)
if(a[i][j]!=0 && i<j)
{
printf("\n%d-->%d",i,j);
for(k=1;k<=b[i];k++)
printf("%c",c1);
}
}
}
OUTPUT
Enter no.of nodes:4
Construct graph
Enter edges for 1:0 1 0 1
Enter edges for 2:1 0 1 0
Enter edges for 3:0 1 0 1
Enter edges for 4:1 0 0 0
MENU
*********************
1. FLODDING WITH OUT SOLUTION
1. FLODDING WITH SOLUTION
**********************
Enter your choice:1
RECEIVED PACKETS ARE
1-->2x
1-->4x
2-->3xx
3-->4xxxx
Enter no.of nodes:4
Construct graph
Enter edges for 1:0 1 0 1
Enter edges for 2:1 0 1 0
Enter edges for 3:0 1 0 1
Enter edges for 4:1 0 0 0
MENU
*********************
1. FLODDING WITH OUT SOLUTION
1. FLODDING WITH SOLUTION
**********************
Enter your choice:2
1-->2x
1-->4x
2-->3x