0% found this document useful (0 votes)
36 views3 pages

Experiment No. 2: AIM: - Write

This program formulates a linear programming problem (LPP) using the simplex method in C++. It takes user input for the objective function, number of variables, coefficients, number of constraints, constraint coefficients, conditions (< or >), and right-hand sides. It then displays the objective function and constraints to show the formulated LPP.

Uploaded by

Prem Mishra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views3 pages

Experiment No. 2: AIM: - Write

This program formulates a linear programming problem (LPP) using the simplex method in C++. It takes user input for the objective function, number of variables, coefficients, number of constraints, constraint coefficients, conditions (< or >), and right-hand sides. It then displays the objective function and constraints to show the formulated LPP.

Uploaded by

Prem Mishra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT NO.

2
AIM: - Write a program in C++ to formulate a LPP by simplex method.

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int i,j,a[10],v;char cond[3],ccond[10];int noc,b[10][10],c,rhs[10];
cout<<"Enter the details of objective function:-";
cout<<"\n\nMax. or Min.";
gets(cond);
cout<<"\n\nEnter the no. of variables:- ";
cin>>v;
cout<<"\n\nEnter the coefficients of the variables:- ";
cout<<"\n";
for(i=1;i<=v;i++)
{
cin>>a[i];
}
cout<<"\n\nEnter the no. of constraint";
cin>>c;
for(i=0;i<c;i++)
{
cout<<"\nEnter the coefficients of constraint number
"<<i+1<<":";
for(j=0;j<v;j++)
{
cin>>b[i][j];
}

cout<<"\nEnter the condition ( > or < ) (= sign will be added


automatically):";
cin>>ccond[i];
cout<<"\nEnter the RHS value of constraint:";
cin>>rhs[i];
}
cout<<"\n\n The objective function is : ";
cout<<"\n\n";
puts(cond);
cout<<"z=";
for(i=1;i<=v;i++)
{
cout<<a[i]<<"x"<<i;
if(i<v)
{
cout<<" + ";
}
}
cout<<"\n\nSubject to:-\n";
for(i=0;i<c;i++)
{
for(j=0;j<v;j++)
{
cout<<b[i][j]<<"x"<<j+1;
if(j<v-1)
{
cout<<" + ";
}
}
cout<<ccond[i];cout<<"=";
cout<<rhs[i];
cout<<"\n";
}
for(i=0;i<v;i++)
{

cout<<"x"<<i+1;
if(i<v-1)
{
cout<<",";
}
}
cout<<">=0";
getch();
}

You might also like