/*Tennis Tournament*/
SOURCE CODE:
#include<stdio.h>
#define SIZE 10
void Schedule(int schedule[SIZE][SIZE],int n);
void Schedule(int Table[SIZE][SIZE],int n)
{
int days,value,row,col;
if(n%2)
value=n+1;
else
value=n;
if(n%2)
days=n;
else
days=n-1;
for(row=0;row<days;row++)
{
for(col=0;col<row;col++)
Table[row][col]=((days+row-col+1)+value)%value;
for(col=row;col<n;col++)
Table[row][col]=((days+row-col)+value)%value;
}
row=0;
for(col=value-2;col>0;col--)
{
row=((row-2)+days)%days;
Table[row][0]=Table[row][col];
Table[row][col]=0;
}
if(value!=n)
for(col=0;col<days;col++)
Table[col][col]=-1;
}
void main(void)
{
int A[SIZE][SIZE];
int n,row,col,days;
clrscr();
printf("Enter the number of players:");
scanf("%d",&n);
if(n%2)
days=n;
else
days=n-1;
Schedule(A,n);
printf("\n Player ->\n");
printf(" ");
for(col=0;col<n;col++)
printf("%7d",col+1);
printf("\n");
printf("Day |");
for(col=0;col<7*n;col++)
printf("-");
printf("\n");
for (row=0;row<days;row++)
{
printf("%7d|",row+1);
for(col=0;col<n;col++)
printf("%7d",A[row][col]+1);
printf("\n");
}
printf("\n");
getch();
}
OUTPUT:
Enter the number of players:8
Player ->
1 2 3 4 5 6 7 8
Day |------------------------------------------------------------
1| 8 7 6 5 4 3 2 1
2| 5 8 7 6 1 4 3 2
3| 2 1 8 7 6 5 4 3
4| 6 3 2 8 7 1 5 4
5| 3 4 1 2 8 7 6 5
6| 7 5 4 3 2 8 1 6
7| 4 6 5 1 3 2 8 7
SOURCE CODE:
#include<stdio.h>
#define SIZE 10
void Schedule(int schedule[SIZE][SIZE],int n);
void Schedule(int Table[SIZE][SIZE],int n)
{
int days,value,row,col;
if(n%2)
value=n+1;
else
value=n;
if(n%2)
days=n;
else
days=n-1;
for(row=0;row<days;row++)
{
for(col=0;col<row;col++)
Table[row][col]=((days+row-col+1)+value)%value;
for(col=row;col<n;col++)
Table[row][col]=((days+row-col)+value)%value;
}
row=0;
for(col=value-2;col>0;col--)
{
row=((row-2)+days)%days;
Table[row][0]=Table[row][col];
Table[row][col]=0;
}
if(value!=n)
for(col=0;col<days;col++)
Table[col][col]=-1;
}
void main(void)
{
int A[SIZE][SIZE];
int n,row,col,days;
clrscr();
printf("Enter the number of players:");
scanf("%d",&n);
if(n%2)
days=n;
else
days=n-1;
Schedule(A,n);
printf("\n Player ->\n");
printf(" ");
for(col=0;col<n;col++)
printf("%7d",col+1);
printf("\n");
printf("Day |");
for(col=0;col<7*n;col++)
printf("-");
printf("\n");
for (row=0;row<days;row++)
{
printf("%7d|",row+1);
for(col=0;col<n;col++)
printf("%7d",A[row][col]+1);
printf("\n");
}
printf("\n");
getch();
}
OUTPUT:
Enter the number of players:8
Player ->
1 2 3 4 5 6 7 8
Day |------------------------------------------------------------
1| 8 7 6 5 4 3 2 1
2| 5 8 7 6 1 4 3 2
3| 2 1 8 7 6 5 4 3
4| 6 3 2 8 7 1 5 4
5| 3 4 1 2 8 7 6 5
6| 7 5 4 3 2 8 1 6
7| 4 6 5 1 3 2 8 7
No comments:
Post a Comment