0% found this document useful (0 votes)
29 views7 pages

#Include #Include: Double While

This C++ program allows the user to input coefficients for two linear equations and then solves the system of equations. It prompts the user to input values for the coefficients a, b, c, d, e, and f. It then displays the equations based on the input values and determines if the system has a unique solution, infinite solutions, or no solution by calculating the determinant. If a unique solution exists, it displays the values of x and y.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views7 pages

#Include #Include: Double While

This C++ program allows the user to input coefficients for two linear equations and then solves the system of equations. It prompts the user to input values for the coefficients a, b, c, d, e, and f. It then displays the equations based on the input values and determines if the system has a unique solution, infinite solutions, or no solution by calculating the determinant. If a unique solution exists, it displays the values of x and y.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

#include <iostream>

#include <limits>
int main()
{
std::cout<<"This program is designed to test two linear equations. \n";
std::cout<<"In order to best solve the system, \n";
std::cout<<"equations will be in the form of a*x + b*y = c. \n";
std::cout<<"and d*x + e*y =f. \n";
std::cout<<"Please enter an integer for a, b, and c. \n";
double a, b, c, d, e, f;
while ((std::cout << "Enter a.")
&& !(std::cin >> a))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
while ((std::cout << "Enter b.")
&& !(std::cin >> b))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
while ((std::cout << "Enter c.")
&& !(std::cin >> c))
{
std::cout << "That's not a number ";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
std::cout<<"Equation 1 is "<<a<<"x +"<<b<<"y ="<<c;
std::cout<<"Please enter an integer for d, e, and f. \n";
while ((std::cout << "Enter d.")

ode to find determinant of a matrix


C program to calculate determinant of a matrix

#include<stdio.h>
int main(){
int a[3][3],i,j;
int determinant=0;
printf("Enter the 9 elements of matrix: ");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
printf("\nThe First matrix is\n");
for(i=0;i<3;i++){
printf("\n");
for(j=0;j<3;j++)
printf("%d\t",a[i][j]);
}
for(i=0;i<3;i++)
determinant = determinant + (a[0][i]*(a[1]
[(i+1)%3]*a[2][(i+2)%3] - a[1][(i+2)%3]*a[2]
[(i+1)%3]));
printf("\nDeterminant of matrix is:
%d",determinant);
return 0;
}

C code for Determinant of 2X2 matrix:


#include<stdio.h>
int main(){
int a[2][2],i,j;
long determinant;
printf("Enter the 4 elements of matrix: ");
for(i=0;i<2;i++)
for(j=0;j<2;j++)
scanf("%d",&a[i][j]);
printf("\nThe matrix is\n");
for(i=0;i<2;i++){
printf("\n");
for(j=0;j<2;j++)
printf("%d\t",a[i][j]);
}
determinant = a[0][0]*a[1][1] - a[1][0]*a[0][1];
printf("\nDeterminant of 2X2 matrix:
%ld",determinant);
}

return 0;

Enter the 4 elements of matrix: 4


8
3
9
The matrix is
4
3

8
9

Determinant of 2X2 matrix: 12


C code for Determinant of 3X3 matrix:

#include<stdio.h>
int main(){
int a[3][3],i,j;
long determinant;

printf("Enter the 9 elements of matrix: ");


for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
printf("\nThe matrix is\n");
for(i=0;i<3;i++){
printf("\n");
for(j=0;j<3;j++)
printf("%d\t",a[i][j]);
}
determinant = a[0][0]*((a[1][1]*a[2][2]) - (a[2]
[1]*a[1][2])) -a[0][1]*(a[1][0]*a[2][2] - a[2]
[0]*a[1][2]) + a[0][2]*(a[1][0]*a[2][1] - a[2]
[0]*a[1][1]);
printf("\nDeterminant of 3X3 matrix:
%ld",determinant);
}

return 0;

Sample output:
Enter the 9 elements of matrix: 1
2
3
4
5
6
7
8

9
The matrix is
1
4
7

2
5
8

3
6
9

Determinant of 3X3 matrix: 0


#include <iostream>

using namespace std;


int main()
{
int m, n, p, a1, c2, b1, d2, f1, g2;
int q, o, r, s, t;
cout<<"Bienvenido, este programa le permite resolver un sistema de
ecuaciones de dos variables\n"<< endl;
cout<<"Por favor introduzca los valores correspondientes a la primera
ecuacin:\n ";
cout<<"\nPor favor introduzca el valor de a: ";
cin>>a1;
cout<<"\nPor favor introduzca el valor de b: ";
cin>>b1;
cout<<"\nPor favor introduzca el valor de f: ";
cin>>f1;
cout<<"\nAhora, introduzca los valores correspondientes a la segunda
ecuacin:\n ";
cout<<"\nPor favor introduzca el valor de c:";
cin>>c2;
cout<<"\nPor favor introduzca el valor de d:";

cin>>d2;
cout<<"\Por favor introduzca el valor de g:";
cin>>g2;
cout<<"La ecuaciones formadas con los datos que han sido ingresados por
usted son \n\n";
if (b1>0){
cout<<"\n "<< a1 <<"x+"<<b1<<"y = "<< f1<< endl;
}
else {
cout<<"\n "<< a1 <<"x-"<<q<<"y = "<< f1<< endl;
}
if (d2>0){
cout<<"\n "<< c2 <<"x+"<<d2<<"y = "<< g2<< "\n\n\n} " <<endl;}
else {
cout<<"\n "<< c2 <<"x-"<<o<<"y = "<< g2<< "\n\n\n " << endl;}

m=(a1*d2)-(c2*b1);
if (m==0) {
cout<<"El sistema tiene infinitas soluciones"<< endl;
}
else if (m==0 && (n!=0 || p!=0)){
cout<<"El sistema no tiene solucin"<< endl;
}
cout<<"D

= "<< m << endl;

cout<<"D(x) = "<< n << endl;


cout<<"D(y) = "<< p << endl;
if {

cout<<"Presione enter para continuar. . .";


cin.get();
cin.get();
return 0;
}
else {
r=(n/m);
s=(p/m);
cout<<"\nX = "<< n<<"/"<< m <<" = "<< r << endl;
cout<<"Y = "<< p<<"/"<< m <<" = "<< s << endl;
cout<<"Las soluciones son {("<< r <<","<< s<<")}"<< endl;
}
return 0;
}

You might also like