/* * To display the jobs that can be run on machines as a 4 X 3 matrix * @author-Karan Narain(karan@iitk.ac.in) * */ #include int main() { int A[4][3],job,machine,i,j; //Initialize the matrix A to 0,indicating that initially no job can be run on any machine for(i=0;i<4;i++) { for(j=0;j<3;j++) { A[i][j]=0; } } for(i=0;i<8;i++) { printf("\nEnter job-machine pair number %d:\n",i+1); scanf("%d",&job); scanf("%d",&machine); //Check for invalid inputs,i.e.job>3 or machine>2 if((job>3)||(machine>2)) { printf("Invalid input.\n"); //Decrement i and continue to repeat this iteration till a valid input is provided i=i-1; /*continue statement stops the current iteration and goes back to the for loop statement.Here i is incremented but since we had decremented i before continue,i gets the same value as before and the iteration is repeated*/ continue; } //set 1 for the cell of the matrix that corresponds to this particular job and machine A[job][machine]=1; } printf("The job-machine matrix is as follows\n"); for(i=0;i<4;i++) { for(j=0;j<3;j++) { printf("%d ",A[i][j]); } printf("\n"); } }