Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ntent-rid-10759140 1/courses/CS-2073-002-28678-201620/AS.pdf CS 2073 Computer Pr

ID: 3679376 • Letter: N

Question

ntent-rid-10759140 1/courses/CS-2073-002-28678-201620/AS.pdf CS 2073 Computer Programming with Engineering Applications Assignment 5 Due March 27, 2016 11:59PM (100 pts) Write a single program that computes the value of the following expressions using functions. Read a selection from the user and repeat the process once the selection has been executed. There must be an option for the User to exit the program. If user enters: 1. A Compute the following: Determinant of 2x2 matrix R Compute the following: Determinant of 3x3 matrix Compute the following: Determinant of 4x4 matrix F Exit the program Exit the calculator IA, 1B, IC, II IERepeat the program Output error message For this assignment, you will need to know . if, if/else, and if/else if/else statements . while (1) loops * switch statements .C functions Be sure to add comments to your code and a header with your name, id, and assignment number The output does not have to match the exact style of the scenarios in the next page, but the code must work according to the format set forth in the instructions. Submit your.c file through the BlackBoard Learn site.

Explanation / Answer


#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>

void main()
{
int determinant(int[5][5],int);// FUNCTIONS
void read(int[5][5],int);
void print(int[5][5],int); // PROTOYPES
int a[5][5],l,n;
int result;
l1:clrscr();
cout<<"

   ENTER ORDER OF MATRIX(MAX. OF 4X4):";
cin>>l>>n;
if(l!=n)
{ //TESTING CONDITION
   cout<<"


               SORRY!!!!!                ONLY SQUARE MATRIX";
   goto l1;
}
read(a,n);
result = determinant(a,n);
print(a,n);
cout<<"


       THE DETERMINANT OF THE ABOVE MATRIX IS:"<<result;
getch();
}


void read(int b[5][5],int m) //FUNCTION FOR READING MATRIX
{
cout<<"


   ENTER "<<m*m<<" ELEMENTS OF MATRIX(ROW-WISE):";
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
   cin>>b[i][j];
}


void print(int b[5][5],int m)
{
clrscr(); //FUNCTION FOR PRINTING MATRIX
cout<<"

   MATRIX IS :-

       ";
for(int i=0;i<m;i++)
{
cout<<"
";
for(int j=0;j<m;j++)
   cout<<"   "<<b[i][j];
}
}

int determinant(int b[5][5],int m) //FUNCTION TO CALCULATE
DETERMINANT
{
int i,j,sum = 0,c[5][5];
if(m==2)
{ //BASE CONDITION
   sum = b[0][0]*b[1][1] - b[0][1]*b[1][0];
   return sum;
}
for(int p=0;p<m;p++)
{
int h = 0,k = 0;
for(i=1;i<m;i++)
{
   for( j=0;j<m;j++)
   {
   if(j==p)
   continue;
   c[h][k] = b[i][j];
   k++;
   if(k == m-1)
   {
       h++;
       k = 0;
   }

   }
}

sum = sum + b[0][p]*pow(-1,p)*determinant(c,m-1);
}
return sum;
}