//Assignment 2
#include <stdio.h>
#include <stdlib.h>
#define max 100
#define cols 5
#define rows 10
void input (int a[][cols], int x);
void display (int a[][cols], int r, int c);
void AvoidBadSchedule (int A[][cols]);
void ComputeAtA ( int At[][rows],int a[][cols], int C[][cols]);
int main()
{
int x=5;// this is for the number of participant in order loop enough times for input
int A[rows][cols]={0};
input(A,x);
printf(“The raw matrix is:\n\n”);
display(A,rows,cols);
printf("\n\n\n");
int At[cols][rows]={0};
int C[cols][cols]={0};
ComputeAtA( At,A,C);
AvoidBadSchedule(A,m,n);
system(“pause”);
return 0;
}
void input (int a[][cols], int x)
{
int i,j,n=0;
while(n<x)
{
printf("input pair : %d\n",n+1);
scanf("%d%d",&i,&j);
if(i==0 && j==0)
{
break;
}
a[i-1][j-1]=1;
n++;
}
}
void display (int a[][cols], int r, int c)
{
int i,j;
for ( i=0; i<r; i++)
{
for(j=0;j<c;j++)
{
printf(" %2d ",a[i][j]);
}
printf("\n");
}
}
void ComputeAtA ( int At[][rows],int a[][cols], int C[][cols])
{
int i,j,k;
//Transpose of the matrix
for(i=0;i<cols;i++)
{
for(j=0;j<rows;j++)
{
At[i][j]=a[j][i];
}
}
// Output of the transposed matrix
printf(“The transposed matrix is:\n\n”);
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
printf(" %2d “,At[i][j]);
}
printf(”\n");
}//end for loop
// Calculation of C
for (i=0;i<cols;i++)
{
for(j=0;j<cols;j++)
// C[i][j]=0;
for (k=0;k<rows;k++)
{
C[i][j] = C[i][j] + At[i][k] * a[k][j];
}
}
// Output of C
printf("\n\nMarix C = At * A is as follows:\n");
printf("\n");
for(i=0;i<cols;i++)
{
for(j=0;j<cols;j++)
{
printf(" %2d “,C[i][j]);
}
printf(”\n");
}//end for loop*/
//Calculation of The number of participants
for (i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if( i == j )
{
printf("\n %d Paricipants wanna attend presentation %d \n",C[i][i],i+1);
}
// printf("\n");
}
}
}// end function ComputeAtA
void AvoidBadSchedule (int A[][cols])
{
int i,j, l1=0,l2=0,l3=0, p1,p2,p3;
for (i=0;i<cols+1;i++)
{
for(j=i+1;j<cols;j++)
{
if(A[i][j]>l1)
{
l1 = A[i][j];
p1=j+1;
}
}
}
for (i=1;i<cols-1;i++)
{
for(j=i+1;j<cols;j++)
{
if(A[i][j]>l2 || A[i][j] != l1 )
{
l2 = A[i][j];
p2=j+1;
}
}
}
for (i=0;i<cols-1;i++)
{
for(j=i+1;j<cols;j++)
{
if( A[i][j] >= 0 || A[i][j] <l1 && A[i][j] <l2)
{
l3 = A[i][j];
p3=j+1;
}
}
}
//Output of the bad schedules
printf(“The following presentations are not to be scheduled at the same time\n”);
l1>1? printf(“Presentation -->%d\n”,p1): printf("");
l2>1? printf(“Presentation -->%d\n”,p2):printf("");
l3>1? printf(“Presentation -->%d\n”,p3):printf("");
}