Académique Documents
Professionnel Documents
Culture Documents
1
About Program
Program in numbers:
225……. lines
22 .……. Variables and Constants ( 10 including functions )
50 ….…. Printf
12 ….…. If
12 ….…. Loops – while and for
4 ………. Functions
57…..…. Comments
2
Program Code
#include<stdio.h>
#define size 10
PrintM(int[size][size],int,int,int);
Sum(int[size][size],int[size][size],int,int);
Sub(int[size][size],int[size][size],int,int);
Det(int[size][size],int,int);
int main()
{
int Operations;
int Metrix1 [size][size]; // The First Aray
int Metrix2 [size][size]; // The Second Aray
int Metrix3 [size][size]; // The 3rd Aray
int i; // i for for first loop
int j; // j for second loop
int counter=0; // Counter for use the operations
int contrun=0; // Counter for use the programs
int E1,E2; // E for user to enter how many time the program run
int N,N1,N2; // N for the first dimension
int M,M1,M2; // M for the second dimension
int Q; // Q for number of metrix in printm
printf("\n\t\t\t College Of Technological Students \n");
printf("\t\t\t Computer Project \n\n");
printf("\t\t\t M A T R I X C A L C U L A T O R \n\n");
printf("\t______________________________________________________________\n\n");
printf(" Welcome To Our Program ^_^ .. \n\n\n");
printf(" How many time you want to re-start the program ?\n *Note : 0
means you wanna run this program just 1 time. \n");
scanf("%d",&E1);
while(E1>=contrun){ //while 1
printf("\n >> *IMPORTANT* : MAXIMUM NUMBER OF ROWS AND
COLUMNS IS : 10 << \n\n");
printf(" \t MATRIX 1 : \n");
printf(" Enter the number of ROWS on Matrix 1,please?\n");
scanf("%d",&N1);
printf(" Enter the number of Columns on Matrix 1,please?\n");
scanf("%d",&M1);
printf(" \n\t MATRIX 2 : \n");
printf(" Enter the number of ROWS on Matrix 2,please?\n");
scanf("%d",&N2);
printf(" Enter the number of Columns on Matrix 2,please?\n");
scanf("%d",&M2);
3
printf("\n How many operations you want to make on this matrixes ?\n
( for example : Press (2) if you wanna make Summation and subtraction ) \n ");
scanf("%d",&E2);
printf(" \n");
for(i=0;i<N1;i++){
for(j=0;j<M1;j++){
printf("Enter the elements of Matrix 1,please?\n");
scanf("%d",&Metrix1[i][j]);
} //second for loop
} //first for loop
printf(" \n");
for(i=0;i<N2;i++){
for(j=0;j<M2;j++){
printf("Enter the elements of Matrix 2,please?\n");
scanf("%d",&Metrix2[i][j]);
} //second for loop
} //first for loop
Q=1; // Q=1 for number of metrix no.1
printf(" \n");
PrintM(Metrix1,N1,M1,Q);
Q=2; // Q=2 for number of metrix no.2
printf(" \n");
PrintM(Metrix2,N2,M2,Q);
printf("\n ...............................................\n");
while(E2>counter){ //while 2
printf("\n\n Choose the operation that you want to do :\n\t 1-
Summation\n\t 2- Subtraction \n\t 3- determinant \n \n\n >> *IMPORTANT* : IF YOU ENTER
CHARACTER YOUR PC WILL HUNG << \n\n");
scanf("%d",&Operations);
if(Operations==1){
printf("\n You Chose Summation : \n");
if(N1==N2){
N=N1;
if(M1==M2){
M=M1;
Sum(Metrix1,Metrix2,N,M);
printf("\n ...............................................\n");
counter++;
} //end of if 2
} //end of if 1
if(N1!=N2){
printf("\n Error ! your matrixs has two different sizes.\n (for
example: if Matrix 1 has 2 row and 4 columns \n >> Matrix 2 must has 2 row and 3
columns also.\n\t Please, run the program again :) ");
counter++;
4
} //for second if
} //end of op 1
if(Operations==2){
printf("You Chose The Subtraction\n");
if(N1==N2){
N=N1;
if(M1==M2){
M=M1;
Sub(Metrix1,Metrix2,N,M);
printf("\n ...............................................\n");
counter++;
} //end of if 2
} //end of if 1
if(N1!=N2){
printf("\n Error ! your matrixs has two different sizes.\n (for
example: if Matrix 1 has 2 row and 4 columns \n >> Matrix 2 must has 2 row and 3
columns also.\n\t Please, run the program again :) ");
counter++;
} //for second if
} // end of op 2
if(Operations==3){
printf("You Chose The determinant\n");
printf("\n >> *IMPORTANT* : MAXIMUM NUMBER OF ROWS AND
COLUMNS IS : 2 only << \n\n");
N=2;
M=2;
for(i=0;i<N;i++){
for(j=0;j<M;j++){
printf("Enter the elements of Matrix 3,please?\n");
scanf("%d",&Metrix3[i][j]);
} //second for loop
} //first for loop
Q=3; // Q=3 for number of metrix no.2
printf(" \n");
PrintM(Metrix3,N,M,Q);
Det(Metrix3,N,M);
counter++;
} // end of op 3
if(Operations>=4){
printf("\n\n You chose incorrect choice ! \n ( Any chose other than
( 1 - 2 - 3 ) is incorrect ) \n\n");
} // end of op >=4
} /*End Of While 2*/
contrun++;
} /*End Of While 1*/
5
printf("\n\n\n\t Thanks for using our program :)\n");
printf("\n\n\t With our best regards,\n");
printf("\t Moutaz & Nser\n");
return 0;
} /*End Of Program*/
6
int s; //for second loop
int d=2;
for(a=0;a<N;a++){
for(s=0;s<M;s++){
Z[a][s]=(double)(B[a][s]-C[a][s]);
printf("\t Sub[%d][%d] = %2.4f",a,s,Z[a][s]);
d++;
if(d%2==0){
printf("\n");
}
} //second for loop
} //first for loop
printf("\n");
} //End of function
/*............................................................................*/
Det(int B[size][size],int N,int M){ //Begining of function
int Z;
Z=(double)((B[0][0]*B[1][1])-(B[0][1]*B[1][0]));
printf("\t Determinant = %d",Z);
printf("\n");
printf("\n ...............................................\n");
} //End of function
/*............................................................................*/
7
Advantages of Program
Disadvantages of Program
8
No Graphics Interface.
9
Determinate Matrixes Sizes
It's main point in matrix calculator. User must be able to determinate the size
of matrix, but when we write direct order:
scanf("%d%d",&N,&M);
Compiler gives us error! After that we know that we can't allocate memory
when program is running by this way. There is something is" Dynamic Memory
Allocation" which is reserving memory in a program moment to moment, as needed,
without having to reserve a fixed amount when the program starts up. To do this we
need to use "malloc" function. But it's was hard to use, so we thought about another
way.
We solve this problem by define variable with fixed value "size=10" and make
"size" is the size of the matrixes. After that we tell the user that the maximum rows
or columns are 10 and the program can't calculate matrix with size more than 10.
10