-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExam_Seat_arrangement
75 lines (75 loc) · 1.26 KB
/
Exam_Seat_arrangement
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int a[10][10]={{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0}};
int m,n,r,i,j,k,sum=1,l;
printf("Enter the dimension of the hall d1 and d2:");
scanf("%d %d",&m,&n);
l=m*n;
if(l>100)
{
printf("This program can't access above 10*10 matrix");
exit(0);
}
printf("Enter the number of students:");
scanf("%d",&r);
if(l%2==0)
{
if(r>(l/2))
{
printf("A maximum of %d students can sit in the hall\n\nSo this hall can't hold %d students ",l/2,r);
exit(0);
}
}
else
{
if(r>(l/2)+1)
{
printf("A maximum of %d students can sit in the hall\n\nSo this hall can't hold %d students",(l/2)+1,r);
exit(0);
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i%2==0)
{
if(j%2==0)
{
a[i][j]=sum++;
if(sum>r)
{
break;
}
}
}
else
{
if(j%2!=0)
{
a[i][j]=sum++;
if(sum>r)
{
break;
}
}
}
}
if(sum>r)
{
break;
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
getch();
}