/*
PROGRAM BY SOUMEN KARMAKAR
College of Engineering and Management ,Kolaghat
3rd Year Information Technology
Note: Compile the program under Linux environment using gcc. If you want to compile it under turbo c then modify the program
*/
// Program to solve matrix Minima (Transportation Problem)
#include <stdio.h>
void input_data(int a[][10],int b[][10],int s[10],int d[10]);
void show_data(int a[][10],int b[][10],int s[10],int d[10]);
void matrix_min(int a[][10],int b[][10],int s[10],int d[10]);
int m,n;
int main(void)
{
int a[10][10],b[10][10],s[10],d[10];
printf("\nEnter the no of supply & demand\n");
scanf("%d %d",&m,&n);
input_data(a,b,s,d);
show_data(a,b,s,d);
matrix_min(a,b,s,d);
return (0);
}
void input_data(int a[][10],int b[][10],int s[10],int d[10])
{
int i,j;
printf("\nEnter the cost matrix\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
b[i][j]=-1;
}
printf("\nEnter the supply \n");
for(i=0;i<m;i++)
scanf("%d",&s[i]);
printf("\nEnter the demand\n");
for(i=0;i<n;i++)
scanf("%d",&d[i]);
}
void show_data(int a[][10],int b[][10],int s[10],int d[10])
{
int i,j;
printf("\n \t\t\tSupply\n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("%d (%d) ",a[i][j],b[i][j]);
}
printf(" | %d",s[i]);
}
printf("\n------------------------\n");
printf("\nDemand ");
printf("%d ",d[i]);
}
void matrix_min(int a[][10],int b[][10],int s[10],int d[10])
{
int i,j,s1,d1,cost,min,t1,t2,sd;
int tag[10][10];
s1=0;
d1=0;
for(i=0;i<m;i++)
{
s1=s1+s[i];
}
printf("\nsupply= %d",s1);
for(j=0;j<n;j++)
{
d1=d1+d[j];
}
printf("\ndemand= %d",d1);
if(s1!=d1)
printf("\nIt is unbalanced\nSo new table is\n\n");
if(s1>d1)
{
n++;
for(i=0;i<m;i++)
{
a[i][n-1]=0;
b[i][n-1]=-1;
}
d[n-1]=s1-d1;
d1=s1;
show_data(a,b,s,d);
}
else if(s1<d1)
{
m++;
for(j=0;j<n;j++)
{
a[m-1][j]=0;
b[m-1][j]=-1;
}
s[m-1]=d1-s1;
s1=d1;
show_data(a,b,s,d);
}
//MAIN CALCULATION
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
tag[i][j]=-1;
}
}
printf("\nTag matrix \n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("%d ",tag[i][j]);
}
}
cost=0;
sd=0;
while(sd!=s1)
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(tag[i][j]==-1)
{
min=a[i][j];
t1=i;
t2=j;
break;
}
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(tag[i][j]==-1)
{
if(min>a[i][j])
{
min=a[i][j];
t1=i;
t2=j;
}
}
}
}
printf("\nMin =%d\n",min);
if(d[t2]==s[t1])
{
cost=cost+a[t1][t2]*s[t1];
b[t1][t2]=s[t1];
sd=sd+s[t1];
d[t2]=0;
s[t1]=0;
show_data(a,b,s,d);
for(j=0;j<n;j++)
{
if(tag[t1][j]==0)
continue;
tag[t1][j]=0;
}
for(i=0;i<m;i++)
{
if(tag[i][t2]==0)
continue;
tag[i][t2]=0;
}
printf("\nTag matrix \n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("%d ",tag[i][j]);
}
}
}
else if(d[t2]>s[t1])
{
cost=cost+a[t1][t2]*s[t1];
b[t1][t2]=s[t1];
sd=sd+s[t1];
d[t2]=d[t2]-s[t1];
s[t1]=0;
show_data(a,b,s,d);
for(j=0;j<n;j++)
{
if(tag[t1][j]==0)
continue;
tag[t1][j]=0;
}
printf("\nTag matrix \n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("%d ",tag[i][j]);
}
}
}
else
{
cost=cost+a[t1][t2]*d[t2];
b[t1][t2]=d[t2];
sd=sd+d[t2];
s[t1]=s[t1]-d[t2];
d[t2]=0;
show_data(a,b,s,d);
for(i=0;i<m;i++)
{
if(tag[i][t2]==0)
continue;
tag[i][t2]=0;
}
printf("\nTag matrix \n");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("%d ",tag[i][j]);
}
}
}
}
printf("\nCost is =%d\n",cost);
}
// Thank You.........
Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.
A c program is also known as a computer program. A singular matrix has no inverse. An equation to determine this would be a/c=f. <<>> The determinant of a singular matix is zero.
C Examples on Matrix OperationsA matrix is a rectangular array of numbers or symbols arranged in rows and columns. The following section contains a list of C programs which perform the operations of Addition, Subtraction and Multiplication on the 2 matrices. The section also deals with evaluating the transpose of a given matrix. The transpose of a matrix is the interchange of rows and columns.The section also has programs on finding the trace of 2 matrices, calculating the sum and difference of two matrices. It also has a C program which is used to perform multiplication of a matrix using recursion.C Program to Calculate the Addition or Subtraction & Trace of 2 MatricesC Program to Find the Transpose of a given MatrixC Program to Compute the Product of Two MatricesC Program to Calculate the Sum & Difference of the MatricesC Program to Perform Matrix Multiplication using Recursion
It's matrix C.
#include <stdio.h> void main() { int a,b,c,i,j; printf("Enter the number of rows for square matrix : "); scanf("%d",&a); for(i=1;i<=a;i++) { for(c=1,j=1;j<=a;j++,c++) { if(c==i) printf("1 "); else printf("0 "); } printf("\n"); } getch(); }
Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.
A c program is also known as a computer program. A singular matrix has no inverse. An equation to determine this would be a/c=f. <<>> The determinant of a singular matix is zero.
How we can addition Two Matrix plz send coding in C language mahesh dhanotiya astah_mahesh@rediff.com how i can built a square matrix in c,
A C program to square matrix is a math problem. In the math problem you write down all the outer boundary values of matrix in a circle, then write down the inner value.
The matrix multiplication in c language : c program is used to multiply matrices with two dimensional array. This program multiplies two matrices which will be entered by the user.
int matrix[][]; // the matrix to find the max in int max = matrix[0][0]; int r,c; for(r = 0; r < 3; ++r) { for(c = 0; c < 3; ++c) { if(matrix[r][c] > max) { max = matrix[r][c]; } } } // max is now the maximum number in matrix
matrix
#include<
Did you know that memory allocation is not needed to display the matrix? However, the C program is to find the sum of all the elements.
Yes, do write. That's what you always have to do when you have got a homework-program.
C Examples on Matrix OperationsA matrix is a rectangular array of numbers or symbols arranged in rows and columns. The following section contains a list of C programs which perform the operations of Addition, Subtraction and Multiplication on the 2 matrices. The section also deals with evaluating the transpose of a given matrix. The transpose of a matrix is the interchange of rows and columns.The section also has programs on finding the trace of 2 matrices, calculating the sum and difference of two matrices. It also has a C program which is used to perform multiplication of a matrix using recursion.C Program to Calculate the Addition or Subtraction & Trace of 2 MatricesC Program to Find the Transpose of a given MatrixC Program to Compute the Product of Two MatricesC Program to Calculate the Sum & Difference of the MatricesC Program to Perform Matrix Multiplication using Recursion
Poor boy