Image

Programs - C++ - Operation Research

Program:


#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,x[10][10],a[10],b[10],n,m,sum=0,sum1=0,sum2=0;
clrscr();
cout<<"Enter the no of Supply & Demand  ";
cin>>n>>m;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{

cout<<"Enter the value of x["<<i<<"]["<<j<<"] ";
cin>>x[i][j];
}
cout<<"
"
;
}
cout<<"Enter the value of Supply ";
for(i=0;i<n;i++)
{
cin>>a[i];
 sum1=sum1+a[i];
 }
cout<<"Enter the value of Demand ";
for(i=0;i<m;i++)
{
cin>>b[i];
sum2=sum2+a[i];
}

if(sum1!=sum2)
cout<<"
Problem is unbalanced"
;
else
  cout<<"
Problem is balanced"
;

i=0,j=0;
while(i<=n && j<=m)
{
if(a[i]<b[j])
  {
  sum =sum+a[i]*x[i][j];
  b[j]=b[j]-a[i];
  a[i]=0;
    i=i+1;
  }
  else if(b[j]<a[i])
 {
 sum =sum+b[j]*x[i][j];
 a[i]=a[i]-b[j];
 b[j]=0;
   j=j+1;
 }
 else
   {
   sum =sum+a[i]*x[i][j];
   a[i]=b[j]=0;
    i=i+1;
    j=j+1;
   }
}
cout<<"
sum is "
<<sum;

getch();
}