Thursday, 9 October 2014

bayzentine program

/*CSEMATTER.BLOGSPOT.IN
Program-implement bayzentine program in c*/

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


int main()
{
int i,j,p[20][20],n,nf,cnt0=0,cnt1=1;
printf("Enter the no. of processes:");
scanf("%d",&n);
printf("Enter the process no. of faulty process:");
scanf("%d",&nf);
for(i=0;i<n;i++)
{
if(i==nf)
{
for(j=0;j<n;j++)
{
if(j!=i)
p[i][j]=random(2);
else
p[i][j]=NULL;}
}
else
{
for(j=0;j<n;j++)
{
if(j!=i)
p[i][j]=1;
else
p[i][j]=NULL;
}}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(p[i][j]==1)
++cnt1;
else if(p[i][j]==0)
++cnt0;
else
continue;
}
if(cnt1>cnt0)
continue;
else
{
printf("Processes are not synchronised \n \n");

}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%d \t",p[i][j]);
}
printf("\n");
}
getch();
}

/*OUTPUT:
Enter the no. of processes:3
Enter the process no. of faulty process:2
Processes are not synchronised

    1   1
1       1
1   0          */

No comments:

Post a Comment