C PROGRAMMING please help me with this question i need the o
C++ PROGRAMMING, please help me with this question, i need the output and a brief explination and where do the numbers come from from the putput???
1) What is the output of the following program? Explain your results. Where do the numbers come from? #include using namespace std; const int SIZE-3; void funct (int MI[SIZEl,int SIZE, int& num1, int& num2); int main( int A1,A2, B1,B2; int A[SIZE) [SIZE (8,1,3),-6,5,3),4,17,-3); int BISIZE) [SIZE--10,8,-13),-3,-2,7,(6,-7,12; funct (A, SIZE,A1,A2) funct (B,SIZE,81,B2) return 0 void funct(int M[SIZE,int SIZE, int&num1;, int& num2) num1#0; num2=0 ; for (int i-0;iSolution
Program:
#include<iostream>
using namespace std;
const int SIZE=3;
void funct(int M[][SIZE],int SIZE, int& num1,int& num2);
int main()
{
int A1,A2,B1,B2;
int A[SIZE][SIZE]={{8,1,3},{-6,5,3},{4,17,-3}};
int B[SIZE][SIZE]={{-10,8,-13},{-3,-2,7},{6,-7,12}};
funct(A,SIZE,A1,A2);
funct(B,SIZE,B1,B2);
cout<<A1<<\" \"<<A2<<\"\ \"<<B1<<\" \"<<B2<<endl;
return 0;
}
void funct(int M[][SIZE],int SIZE,int& num1,int& num2)
{
num1=0;
num2=0;
for(int i=0;i<SIZE;i++)
{
for(int j=0;j<SIZE;j++)
{
if(i==j)
num1 +=M[i][j]; //here if i=j then the first elemtns of all set is added with last elements in all sets in A
else
num2 +=M[i][j]; //here if I not equals to j then the first elemtns of all set is added with last elements in all sets in A
}
}
}
Output: The output for above code is as follows
10 22
0 -2
Explanation:A1= 10 { {8+(-6)+4 + [ 1+3+3-3]} ={ 6 + [ 4 ] }={10} }
A2=22 { { 1+5+17 + [ (-6) +5 + 3 - 3 ] = { 23 + [ - 1 ] }= 22 }
B1= 0 { 8 - 13 ( - 2 + 7 ) = - 5 +5 =0 }
B2=-2
