You are on page 1of 5

#include<stdio.

h>
#include<string.h>
#include<stdlib.h>
//DECLARATIONS
void squareMDim(int *m);
void nonSquareMDim(int *m);
void errorMSG();
int ifSquare(int c);
void chose_operation(void);
void is_propper(char c);
int is__doable(int d, char c);

//

#define MaxT 4
#define MaxD 10

//retarded strings and shit like that


char first[]={"prve"};
char second[]={"druge"};
char third[]={"trece"};
char fourth[]={"cetvrte"};
int mHeight[MaxT];
int mLength[MaxT];
//

//T
//D

for Tables
for Dimension

//m

for matrix

//DEFINITIONS
void errorMSG(){
printf("Greska. Pritisnite enter.\n");
getchar();
getchar();
system("clear");
exit(EXIT_FAILURE);
}
void chose_operation(void){
char p;
printf("\nOdaberite operaciju nad matricama: \n");
printf("Sabiranje matrica: S\n");
printf("Oduzimanje matrica: O\n");
printf("Mnozenje matrica: M\n");
getchar();
p=getchar();

if( p!='s' || p!='S' || p!='O' || p!='o' || p!='M' || p!='m')


errorMSG();
else{
if(p=='s' || p=='S')
matrixAdd();
if(p=='o' || p=='O')
matrixSub();
}
}
//*********************************************************************//
//Loading matrix dimensions
void squareMDim(int *m){
printf("Unesite dimenziju kvadratne matrice ");
printf("(maksimalno 10):\n");
scanf("%d", m);
if(*m<=1)
errorMSG();
printf("Uneta dimenzija kvadratne matrice: ");
printf("%dx%d\n", *m, *m);
}
void nonSquareMDim(int *m){
int c=1;
//matrix counter
int t=*m;
int x=0;
//for printing dimensions
while(c<=t){
int k=0;
if(c==1){
int i=0;
int j=strlen(first);
printf("Unesite broj redova ");
while(i<=j){
printf("%c", first[i-1]);
i++;
}
i=0;
printf(" matrice ");
printf("(maksimalno 10);\n");
scanf("%d", &mHeight[k]);
if(mHeight[k]>MaxD-1 || mHeight[k]<2){
errorMSG();
}
printf("Unesite broj kolona ");
while(i<=j){
printf("%c", first[i-1]);
i++;
}
printf(" matrice ");
printf("(maksimalno 10);\n");
scanf("%d", &mLength[k]);
if(mLength[k]>MaxD-1){
errorMSG();
}
}
k++;

if(c==2){
int i=1;
int j=strlen(second);
printf("Unesite broj redova ");
while(i<=j){
printf("%c", second[i-1]);
i++;
}
i=1;
printf(" matrice ");
printf("(maksimalno 10);\n");
scanf("%d", &mHeight[k]);
if(mHeight[k]>MaxD-1 || mHeight[k]<2){
errorMSG();
}
printf("Unesite broj kolona ");
while(i<=j){
printf("%c", second[i-1]);
i++;
}
printf(" matrice ");
printf("(maksimalno 10);\n");
scanf("%d", &mLength[k]);
if(mLength[k]>MaxD-1){
errorMSG();
}
}
k++;
if(c==3){
int i=1;
int j=strlen(third);
printf("Unesite broj redova ");
while(i<=j){
printf("%c", third[i-1]);
i++;
}
i=1;
printf(" matrice ");
printf("(maksimalno 10);\n");
scanf("%d", &mHeight[k]);
if(mHeight[k]>MaxD-1 || mHeight[k]<2){
errorMSG();
}
printf("Unesite broj kolona ");
while(i<=j){
printf("%c", third[i-1]);
i++;
}
printf(" matrice ");
printf("(maksimalno 10);\n");
scanf("%d", &mLength[k]);
if(mLength[k]>MaxD-1){
errorMSG();
}
}
k++;
if(c==4){
int i=1;
int j=strlen(fourth);
printf("Unesite broj redova ");

while(i<=j){
printf("%c", fourth[i-1]);
i++;
}
i=1;
printf(" matrice ");
printf("(maksimalno 10);\n");
scanf("%d", &mHeight[k]);
if(mHeight[k]>MaxD-1 || mHeight[k]<2){
errorMSG();
}
printf("Unesite broj kolona ");
while(i<=j){
printf("%c", fourth[i-1]);
i++;
}
printf(" matrice ");
printf("(maksimalno 10);\n");
scanf("%d", &mLength[k]);
if(mLength[k]>MaxD-1){
errorMSG();
}
}
c++;
}
printf("Unete dimenzije:\n");
printf("Prve matrice:
%dx%d",mHeight[x], mLength[x]);
x++;
printf("\nDruge matrice: %dx%d",mHeight[x], mLength[x]);
x++;
if(c>3)
printf("\nTrece matrice: %dx%d",mHeight[x], mLength[x]);
x++;
if(c>4)
printf("\nCetvrte matrice: %dx%d",mHeight[x], mLength[x]);
}
//*********************************************************************//
//Matrix dimensions are now located in arrays called mHeight
//and mLength.
//*********************************************************************//
//Checking if non-square matrixes are actually square and have the same
//dimension, but the user is just being an asshole
//PS - CHECKS IN GENERAL
int ifSquare(int c){
int a, i=1;
a=mHeight[0];
while(i<=c){
if(a!=mHeight[i])
return 0;
i++;
}
i=0;
while(i<=c){
if(a!=mLength[i])
return 0;
i++;

}
return 1;
}
void is_propper(char c){
if(c!='S' || c!='O' || c!='M')
errorMSG();
}
int is_doable(int d, char c){
//c is a selected operation, d is a number of matrix loaded
int i=1, t=mHeight[0], p=mLength[0];
is_propper(c);
while(i<=d){
if( !(t==mHeight[i]) )
errorMSG();
if( !(p==mLength[i]) )
errorMSG();
i++;
}
return 1;
}
//*********************************************************************//

You might also like