aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Random/mandelbrot.c55
-rw-r--r--Random/matrixTeste.c40
-rw-r--r--Random/mergesort.cpp49
-rw-r--r--Uni/agenda.c278
-rw-r--r--Uni/primeiro_trab.c461
5 files changed, 883 insertions, 0 deletions
diff --git a/Random/mandelbrot.c b/Random/mandelbrot.c
new file mode 100644
index 0000000..9f8a796
--- /dev/null
+++ b/Random/mandelbrot.c
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <complex.h>
+#include <math.h>
+#define ite 500
+
+double map(double x, double p1, double p2, double c1, double c2);
+double mandel(double y, double x);
+
+int main(){
+ const int dimx = 800, dimy = 800;
+ int i, j;
+ FILE *fp = fopen("out.ppm", "wb");
+
+ fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy);
+ int c;
+ unsigned char color[3];
+ unsigned char temp;
+ for(j=-dimy/2; j<dimy/2; ++j){
+ for(i=-dimx/2; i<dimx/2; ++i){
+ temp = (int)mandel(map(j, -dimx/2, dimx/2, -2, 2), map(i, -dimx/2, dimx/2, -2, 2));
+ color[0] = temp;
+ color[1] = temp;
+ color[2] = temp;
+ fwrite(color, 3, 1, fp);
+ }
+ }
+
+ fclose(fp);
+ return 0;
+}
+
+double mandel(double y, double x){
+ int i;
+ double ca = x,
+ cb = y;
+ double zx, zy, tzx, tzy;
+ zx = x;
+ zy = y;
+ for(i=0; i<ite; ++i){
+ tzx = zx;
+ tzy = zy;
+ zx = tzx*tzx - tzy*tzy + ca;
+ zy = 2*tzx*tzy + cb;
+ if(zx*zx + zy*zy > 4)
+ break;
+ }
+
+ return map(i, ite, 0, 0, 255);
+}
+
+
+double map(double x, double p1, double p2, double c1, double c2){
+ return 1.0*(x-p1)*(c2-c1)/(p2-p1) + c1;
+} \ No newline at end of file
diff --git a/Random/matrixTeste.c b/Random/matrixTeste.c
new file mode 100644
index 0000000..436e9c9
--- /dev/null
+++ b/Random/matrixTeste.c
@@ -0,0 +1,40 @@
+#include <stdio.h>
+
+void solve(int t){
+ int a, i, j , k, n;
+ int matrix[101][101];
+ a=0;
+ if (!(t%2))
+ n = t/2;
+ else
+ n = t/2 + 1;
+ for (k = 0; k<n; ++k){
+ for (i = a; i < t-a; ++i){
+ for (j = a; j < t-a; ++j){
+ matrix[i][j]=a+1;
+ }
+ }
+ ++a;
+ }
+
+
+ for (i = 0; i < t; ++i){
+ for (j = 0; j < t; ++j){
+ printf("%d ", matrix[i][j]);
+ }
+ printf("\n");
+ }
+ printf("\n");
+}
+
+
+int main(){
+
+ int t;
+ do{
+ scanf("%d", &t);
+ solve(t);
+ }while(t!=0);
+
+ return 0;
+}
diff --git a/Random/mergesort.cpp b/Random/mergesort.cpp
new file mode 100644
index 0000000..82bd33b
--- /dev/null
+++ b/Random/mergesort.cpp
@@ -0,0 +1,49 @@
+#include <bits/stdc++.h>
+using namespace std;
+
+
+void merge(int *A, int p, int q, int r){
+ int n1 = q - p + 1;
+ int n2 = r - q;
+ int L[n1];
+ int R[n2];
+
+ for(int i = 0; i<n1; ++i)
+ L[i] = A[p+i];
+ for(int j = 0; j<n2; ++j)
+ R[j] = A[q+1+j];
+
+ int i = 0, j = 0;
+
+ for(int k = p; k <= r; ++k){
+ if(L[i] <= R[j] && i < n1){
+ A[k] = L[i];
+ ++i;
+ }else{
+ A[k] = R[j];
+ ++j;
+ }
+ }
+
+}
+void merge_sort(int *A, int p, int r){
+ if(p<r){
+ int q = (p+r)/2;
+ merge_sort(A, p, q);
+ merge_sort(A, q+1, r);
+ merge(A, p, q, r);
+ }
+}
+
+int main(){
+
+ int A[10]={9,8,7,6,5,4,3,2,1,0};
+ int p = 0, r = 9;
+ merge_sort(A, p, r);
+
+ for(int i = 0; i < r+1; ++i)
+ printf("%d|", A[i]);
+
+ cout << "\n";
+ return 0;
+} \ No newline at end of file
diff --git a/Uni/agenda.c b/Uni/agenda.c
new file mode 100644
index 0000000..7a625c8
--- /dev/null
+++ b/Uni/agenda.c
@@ -0,0 +1,278 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+
+typedef struct{
+ unsigned long long int pos;
+ unsigned int ano, mes, dia;
+ unsigned int hora, minutos;
+ char texto[1024];
+}agenda;
+
+typedef struct Node{
+ agenda v;
+ struct Node* next;
+}node;
+
+node* create(agenda v){
+ node* tmp = (node*)malloc(sizeof(node));
+ tmp->next = NULL;
+ tmp->v = v;
+ return tmp;
+}
+
+agenda ler(){
+ agenda v;
+ do{
+ printf("insira no formato\n");
+ printf("data [31/12/0000]: ");
+ scanf("%d/%d/%d", &v.dia, &v.mes, &v.ano);
+ }while(v.dia > 31 || v.mes > 12 );
+
+ do{
+ printf("insira no formato\n");
+ printf("horario [23:59]: ");
+ scanf("%d:%d", &v.hora, &v.minutos);
+ }while(v.hora > 23 || v.minutos > 59);
+
+ printf("Compromisso: \n");
+ scanf(" %[^\n]", v.texto);
+
+ v.pos = v.minutos + 60*v.hora + 24*60*v.dia + 31*24*60*v.mes + 12*31*24*60*v.ano;
+ return v;
+}
+
+void print_comp(agenda v){
+ printf("\nData: %02u/%02u/%04u\n", v.dia, v.mes, v.ano);
+ printf("Horario: %02u:%02u\n", v.hora, v.minutos);
+ printf("%s\n", v.texto);
+}
+
+void add_compromisso(agenda v, node** head){
+ node* tmp = create(v);
+ if(*head == NULL){
+ *head = tmp;
+ return;
+ }
+ if((*head)->v.pos > tmp->v.pos){
+ tmp->next = *head;
+ *head = tmp;
+ return;
+ }
+
+ node* aux = *head;
+ node* ant;
+ while(aux != NULL && aux->v.pos < tmp->v.pos){
+ ant = aux;
+ aux = aux->next;
+ }
+ if(aux == NULL){
+ ant->next = tmp;
+ }else{
+ tmp->next = ant->next;
+ ant->next = tmp;
+ }
+}
+
+void print_agenda(node* head){
+ while(head != NULL){
+ print_comp(head->v);
+ head = head->next;
+ }
+}
+
+void remove_compromisso(unsigned long long int pos, node** head){
+ bool ini = false;
+ while((*head) != NULL && (*head)->v.pos >= pos && (*head)->v.pos <= pos+60*23+59){
+ node* tmp = *head;
+ *head = (*head)->next;
+ free(tmp);
+ ini = true;
+ }
+ if(ini) return;
+
+ node* tmp = (*head)->next;
+ node* ant = *head;
+ while(tmp != NULL){
+ bool deletou = false;
+ node* del = tmp;
+ if(tmp != NULL && tmp->v.pos >= pos && tmp->v.pos <= pos+60*23+59){
+ ant->next = tmp->next;
+ deletou = true;
+ }
+ if(deletou){
+ ant = ant;
+ free(del);
+ }
+ else
+ ant = tmp;
+ tmp = tmp->next;
+ }
+}
+
+void consulta_data(unsigned long long int pos, node* head){
+ while(head != NULL){
+ if(head != NULL && head->v.pos >= pos && head->v.pos <= pos+60*23+59)
+ print_comp(head->v);
+ head = head->next;
+ }
+}
+
+void remove_comp_palavra(char* palavra, node** head){
+ if(*head == NULL) return;
+
+ node* tmp = *head;
+ int cont = 0;
+ while(tmp != NULL){
+ if(strstr(tmp->v.texto, palavra) != NULL){
+ printf("---------%d---------", cont+1);
+ printf("\nData: %02u/%02u/%04u\n", tmp->v.dia, tmp->v.mes, tmp->v.ano);
+ printf("Horario: %02u:%02u\n", tmp->v.hora, tmp->v.minutos);
+ printf("%s\n\n", tmp->v.texto);
+ cont++;
+ }
+ tmp = tmp->next;
+ }
+ if(cont == 0) return;
+
+ int esc=1;
+ do{
+ if(esc > cont || esc <= 0) printf("Insira um valor valido: ");
+ else printf("Escolha um compromisso para deletar: ");
+ scanf("%d", &esc);
+ }while(esc <= 0 || esc > cont);
+
+ tmp = *head;
+ node* ant;
+ cont = 0;
+ while(tmp != NULL){
+ if(strstr(tmp->v.texto, palavra) != NULL){
+ cont++;
+ if(cont == esc){
+ if(tmp == *head){
+ *head = tmp->next;
+ free(tmp);
+ }else{
+ ant->next = tmp->next;
+ free(tmp);
+ }
+ return;
+ }
+ }
+ ant = tmp;
+ tmp = tmp->next;
+ }
+}
+
+void print_comp_palavra(char* palavra, node** head){
+ if(*head == NULL) return;
+
+ node* tmp = *head;
+ int cont = 0;
+ while(tmp != NULL){
+ if(strstr(tmp->v.texto, palavra) != NULL){
+ printf("\nData: %02u/%02u/%04u\n", tmp->v.dia, tmp->v.mes, tmp->v.ano);
+ printf("Horario: %02u:%02u\n", tmp->v.hora, tmp->v.minutos);
+ printf("%s\n", tmp->v.texto);
+ cont++;
+ }
+ tmp = tmp->next;
+ }
+}
+
+void altera_comp_palavra(char* palavra, node** head){
+ if(*head == NULL) return;
+
+ node* tmp = *head;
+ int cont = 0;
+ while(tmp != NULL){
+ if(strstr(tmp->v.texto, palavra) != NULL){
+ printf("---------%d---------", cont+1);
+ printf("\nData: %02u/%02u/%04u\n", tmp->v.dia, tmp->v.mes, tmp->v.ano);
+ printf("Horario: %02u:%02u\n", tmp->v.hora, tmp->v.minutos);
+ printf("%s\n\n", tmp->v.texto);
+ cont++;
+ }
+ tmp = tmp->next;
+ }
+ if(cont == 0) return;
+
+ int esc=1;
+ do{
+ if(esc > cont || esc <= 0) printf("Insira um valor valido: ");
+ else printf("Escolha um compromisso para alterar: ");
+ scanf("%d", &esc);
+ }while(esc <= 0 || esc > cont);
+
+ tmp = *head;
+ node* ant;
+ cont = 0;
+ while(tmp != NULL){
+ if(strstr(tmp->v.texto, palavra) != NULL){
+ cont++;
+ if(cont == esc){
+ printf("Novo compromisso: \n");
+ scanf(" %[^\n]", tmp->v.texto);
+ return;
+ }
+ }
+ ant = tmp;
+ tmp = tmp->next;
+ }
+}
+
+int main(){
+ node* head = NULL;
+ while(1){
+ int esc=0;
+ scanf("%d", &esc);
+ if(esc == 1){
+ agenda v = ler();
+ //print_comp(v);
+ add_compromisso(v, &head);
+ }
+ if(esc == 2){
+ print_agenda(head);
+ }
+ if(esc == 3){
+ char palavra[128];
+ printf("Texto para procurar: ");
+ scanf(" %s", palavra);
+ remove_comp_palavra(palavra, &head);
+ }
+ if(esc == 4){
+ unsigned long long int pos;
+ int dia, mes, ano;
+ printf("data [31/12/0000]: ");
+ scanf("%d/%d/%d", &dia, &mes, &ano);
+ pos = 24*60*dia + 31*24*60*mes + 12*31*24*60*ano;
+ consulta_data(pos, head);
+ }
+ if(esc == 5){
+ char palavra[128];
+ printf("Texto para procurar: ");
+ scanf(" %s", palavra);
+ print_comp_palavra(palavra, &head);
+ }
+ if(esc == 6){
+ char palavra[128];
+ printf("Texto para procurar: ");
+ scanf(" %s", palavra);
+ altera_comp_palavra(palavra, &head);
+ }
+ if(esc == 9){
+ unsigned long long int pos;
+ int dia, mes, ano;
+ printf("data [31/12/0000]: ");
+ scanf("%d/%d/%d", &dia, &mes, &ano);
+ pos = 24*60*dia + 31*24*60*mes + 12*31*24*60*ano;
+ remove_compromisso(pos ,&head);
+ }
+ if(esc == 10) break;
+ }
+ return 1;
+}
+
+// TODO: arrumar os inputs da agenda
+// TODO: 3 5
diff --git a/Uni/primeiro_trab.c b/Uni/primeiro_trab.c
new file mode 100644
index 0000000..16f0e87
--- /dev/null
+++ b/Uni/primeiro_trab.c
@@ -0,0 +1,461 @@
+#include <stdio.h>
+#include <ncurses.h>
+#include <string.h>
+#define tam 50
+#define altura 12
+
+void bubble_sort(int array[tam], int col);
+void create_matrix( int matrix[tam][tam], int x, int y);
+void matrixcpy( int matrixcpy[tam][tam], int matrix[tam][tam], int x, int y );
+void show_matrix( int matrix[tam][tam], int x, int y );
+void change_lines( int matrix[tam][tam], int col, int linx, int liny );
+void change_colums( int matrix[tam][tam], int lin, int colx, int coly );
+int is_square_matrix( int x, int y );
+int change_diag( int matrix[tam][tam], int lin, int col );
+int is_sym_matrix( int matrix[tam][tam], int lin, int col );
+int is_magic_square( int matrix[tam][tam], int lin, int col );
+int is_latin_square( int matrix[tam][tam], int lin, int col );
+int is_permut_matrix(int matrix[tam][tam], int lin, int col);
+
+void clear_matrixwin(int startY, int startX, int maxY, int maxX);
+void show_matrix_win2( int matrix[tam][tam], int x, int y);
+
+int yMax, xMax;
+int startX, startY;
+
+int main(){
+ int matrix[tam][tam], new_matrix[tam][tam];
+ int lin, col, lin1, lin2;
+
+
+ /* printf("linha: coluna:\n");
+ scanf("%d %d", &lin, &col);
+ create_matrix(matrix, lin, col);
+ matrixcpy(new_matrix, matrix, lin, col);
+ printf("%d\n", is_permut_matrix(new_matrix, lin, col));
+ show_matrix(new_matrix, lin, col);
+ */
+ initscr();
+ noecho();
+ cbreak();
+
+ const char * menu_itens[9] = {
+ "Ler Matriz",
+ "Trocar elementos da linha X pela linha Y",
+ "Trocar elementos da coluna X pela coluna Y",
+ "Trocar elementos da DP com DS",
+ "Verificar se a matriz e simetrica",
+ "Verificar se a matriz e um quadrado magico",
+ "Verificar se a matriz e quadrado latino",
+ "Verificar se a matriz e matriz de permutacao",
+ "Sair"};
+
+ int matrixwinY, matrixwinX;
+ int mwinyMax, mwinxMax;
+
+ getmaxyx(stdscr, yMax, xMax);
+ getbegyx(stdscr, startY, startX);
+
+ WINDOW * menuwin = newwin(altura, xMax, startY, startX);
+ WINDOW * matrixwin = newwin(yMax-altura, xMax/2, startY+altura, startX);
+ WINDOW * showwin = newwin(yMax-altura, xMax/2, startY+altura, startX+xMax/2);
+
+ getmaxyx(matrixwin, mwinyMax, mwinxMax);
+ getbegyx(matrixwin, matrixwinY, matrixwinX);
+
+ box(menuwin, 0, 0);
+ box(matrixwin, 0, 0);
+ box(showwin, 0, 0);
+
+
+ mvwprintw(matrixwin, 0, 1, "Sua-Matriz");
+ mvwprintw(showwin, 0, 1, "Resultado");
+ mvwprintw(menuwin, 0, 1, "Menu");
+
+ refresh();
+ wrefresh(menuwin);
+ wrefresh(matrixwin);
+ wrefresh(showwin);
+
+ keypad(menuwin, TRUE);
+ int seta;
+ int mark=0;
+ int tem_matriz=0;
+ //do{
+ comeco:
+ matrixcpy(matrix, new_matrix, lin, col);
+ while(1){
+ for(int i = 0; i<9; ++i){
+ if(i==mark)
+ wattron(menuwin, A_REVERSE);
+ mvwprintw(menuwin, i+2, 1, menu_itens[i]);
+ wattroff(menuwin, A_REVERSE);
+ }
+ seta = wgetch(menuwin);
+
+ switch(seta){
+ case KEY_UP:
+ mark--;
+
+ if(mark < 0)
+ mark = 8;
+ break;
+
+ case KEY_DOWN:
+ mark++;
+
+ if (mark >=9)
+ mark = 0;
+ break;
+
+ default:
+ break;
+ }
+ if (mark==0)
+ tem_matriz=1;
+
+ if (seta==10 && tem_matriz || mark==8 && seta==10)
+ break;
+
+ }
+
+
+
+ if(mark==0){
+ clear_matrixwin(startY+altura, startX,yMax-altura, xMax/2);
+ mvprintw(startY+altura+1,startX+1, "Digite quantas linhas e colunas a matriz tera, e pressione enter: ");
+ refresh();
+ scanf("%d", &lin);
+ mvprintw(startY+altura+2,startX+1,"Linhas: %d", lin);
+ refresh();
+ scanf("%d", &col);
+ mvprintw(startY+altura+3,startX+1,"Colunas: %d", col);
+ refresh();
+ mvprintw(startY+altura+4,startX+1,"Pressione uma tecla para continuar...");
+ getch();
+ clear_matrixwin(startY+altura, startX,yMax-altura, xMax/2);
+ create_matrix(matrix, lin, col);
+ matrixcpy(new_matrix, matrix, lin, col);
+ }
+ if(mark==1){
+ clear_matrixwin(startY+altura, startX,yMax-altura, xMax/2);
+ mvprintw(startY+altura+1,startX+1, "Digite o valor das linhas e clique enter");
+ refresh();
+ scanf("%d", &lin1);
+ mvprintw(startY+altura+2,startX+1,"Linha: %d", lin1);
+ refresh();
+ scanf("%d", &lin2);
+ mvprintw(startY+altura+3,startX+1,"Linha: %d", lin2);
+ refresh();
+ mvprintw(startY+altura+4,startX+1,"Pressione uma tecla para continuar...");
+ getch();
+ change_lines(matrix, col, lin1, lin2);
+ show_matrix(matrix, lin, col);
+ clear_matrixwin(startY+altura, startX,yMax-altura, xMax/2);
+ show_matrix_win2(new_matrix, lin, col);
+ }
+
+ if(mark==2){
+ clear_matrixwin(startY+altura, startX,yMax-altura, xMax/2);
+ mvprintw(startY+altura+1,startX+1, "Digite o valor das colunas e clique enter");
+ refresh();
+ scanf("%d", &lin1);
+ mvprintw(startY+altura+2,startX+1,"Linha: %d", lin1);
+ refresh();
+ scanf("%d", &lin2);
+ mvprintw(startY+altura+3,startX+1,"Linha: %d", lin2);
+ refresh();
+ mvprintw(startY+altura+4,startX+1,"Pressione uma tecla para continuar...");
+ getch();
+ change_colums(matrix, col, lin1, lin2);
+ show_matrix(matrix, lin, col);
+ clear_matrixwin(startY+altura, startX,yMax-altura, xMax/2);
+ show_matrix_win2(new_matrix, lin, col);
+ }
+
+ if(mark==3){
+
+ change_diag(matrix, lin, col);
+ show_matrix(matrix, lin, col);
+ clear_matrixwin(startY+altura, startX,yMax-altura, xMax/2);
+ show_matrix_win2(new_matrix, lin, col);
+ }
+ if(mark==4){
+ clear_matrixwin(startY+altura, startX,yMax-altura, xMax/2);
+
+ if(is_sym_matrix(matrix, lin, col)){
+ mvprintw(yMax/2+6,xMax/4-11,"E uma matriz simetrica");
+ refresh();
+ }else{
+ mvprintw(yMax/2+6,xMax/4-13,"Nao e uma matriz simetrica");
+ refresh();
+ }
+ }
+ if(mark==5){
+ clear_matrixwin(startY+altura, startX,yMax-altura, xMax/2);
+
+ if(is_magic_square(matrix, lin, col)){
+ mvprintw(yMax/2+6,xMax/4-10,"E um quadrado magico");
+ refresh();
+ }else{
+ mvprintw(yMax/2+6,xMax/4-12,"Nao e um quadrado magico");
+ refresh();
+ }
+ }
+ if(mark==6){
+ clear_matrixwin(startY+altura, startX,yMax-altura, xMax/2);
+
+ if(is_latin_square(matrix, lin, col)){
+ mvprintw(yMax/2+6,xMax/4-10,"E um quadrado latino");
+ refresh();
+ }else{
+ mvprintw(yMax/2+6,xMax/4-12,"Nao e um quadrado latino");
+ refresh();
+ }
+ }
+ if(mark==7){
+ clear_matrixwin(startY+altura, startX,yMax-altura, xMax/2);
+
+ if(is_permut_matrix(matrix, lin, col)){
+ mvprintw(yMax/2+6,xMax/4-12,"E uma matriz permutacao");
+ refresh();
+ }else{
+ mvprintw(yMax/2+6,xMax/4-14,"Nao e uma matriz permutacao");
+ refresh();
+ }
+ }
+
+ if(mark==8)
+ goto sair;
+ goto comeco;
+ sair:
+ //}while(mark != 8);
+
+ //create_matrix(matrix, 3, 3);
+ //getch();
+ //clear_matrixwin(startY+altura, startX,yMax-altura, xMax/2);
+ //create_matrix(matrix, 3, 3);
+
+
+
+
+ endwin();
+
+
+ return 0;
+}
+
+int is_permut_matrix(int matrix[tam][tam], int lin, int col){
+ int soma = 1, soma1, soma2;
+ int teste[tam][tam];
+ matrixcpy(teste, matrix, lin, col);
+
+ for(int i=0; i<lin; ++i){
+ soma1 = soma2 = 0;
+ for(int j=0; j<col; ++j){
+ soma1 += matrix[i][j];
+ soma2 += matrix[j][i];
+ }
+ if (soma1 != soma || soma2 != soma) return 0;
+ }
+
+ for(int i=0; i<lin; ++i){
+ bubble_sort(teste[i], col);
+ }
+ //show_matrix(teste, lin,col);
+ //verifica os valores
+ for(int i=0; i<lin; ++i){
+ for(int j=0; j<col; ++j){
+ if(teste[i][j] != 0 && j<col-1) return 0;
+ else if (teste[i][col-1] != 1) return 0;
+ }
+ }
+
+ return 1;
+}
+
+void bubble_sort(int array[tam], int col){
+ int aux;
+ for (int i=0; i<col; ++i){
+ for (int j=0; j<col; ++j){
+ if (array[i] < array[j]){
+ aux = array[i];
+ array[i] = array[j];
+ array[j] = aux;
+ }
+ }
+ }
+}
+
+int is_latin_square( int matrix[tam][tam], int lin, int col){
+ int soma = 0, soma1, soma2;
+ int teste[tam][tam];
+ matrixcpy(teste, matrix, lin, col);
+
+ for(int i=1; i<=lin; ++i)
+ soma += i;
+
+ for(int i=0; i<lin; ++i){
+ soma1 = soma2 = 0;
+ for(int j=0; j<col; ++j){
+ soma1 += matrix[i][j];
+ soma2 += matrix[j][i];
+ }
+ if (soma1 != soma || soma2 != soma) return 0;
+ }
+
+ //arruma matriz
+ for(int i=0; i<lin; ++i){
+ bubble_sort(teste[i], col);
+ }
+ //verifica os valores
+ for(int i=0; i<lin; ++i){
+ for(int j=0; j<col; ++j){
+ if(teste[i][0] != 1 ) return 0;
+ else if (teste[i][j] != teste[i][j-1] + 1) return 0;
+ }
+ }
+
+ return 1;
+}
+
+int is_magic_square( int matrix[tam][tam], int lin, int col ){
+ int soma, aux;
+ soma = aux = 0;
+ for (int i=0; i<lin; ++i){
+ soma += matrix[i][i];
+ }
+ for (int i=0; i<lin; ++i){
+ aux += matrix[i][lin-1-i];
+ }
+ if( aux != soma) return 0;
+
+ for (int i=0; i<lin; ++i){
+ aux = 0;
+ for (int j=0; j<col; ++j){
+ aux += matrix[i][j];
+ }
+ if ( aux != soma ) return 0;
+ }
+
+ for (int i=0; i<lin; ++i){
+ aux = 0;
+ for (int j=0; j<col; ++j){
+ aux += matrix[j][i];
+ }
+ if ( aux != soma ) return 0;
+ }
+
+ return 1;
+
+}
+
+int is_sym_matrix(int matrix[tam][tam], int lin, int col){
+ //int transposta[tam][tam];
+ int ver=1;
+ if( !is_square_matrix(lin, col) )
+ return 0;
+ else{
+ /*criar At
+ for( int i=0; i<lin; ++i ){
+ for( int j=0; j<col; ++j ){
+ transposta[j][i] = matrix[i][j];
+ }
+ }*/
+ for( int i=0; i<lin; ++i ){
+ for( int j=0; j<col; ++j ){
+ if( matrix[j][i] != matrix[i][j] ){
+ ver = 0;
+ }
+ }
+ }
+
+ return ver;
+ }
+}
+
+int is_square_matrix(int x, int y){
+ return (x==y) ? 1:0;
+}
+
+int change_diag(int matrix[tam][tam], int lin, int col){
+ int aux, soma=lin-1;
+ if(!is_square_matrix(lin, col)){
+ printf("Impossivel, nao e uma matrix quadrada\n");
+ return 0;
+ }else{
+ for( int i=0; i<lin; ++i){
+ aux = matrix[i][i];
+ matrix[i][i] = matrix[i][soma-i];
+ matrix[i][soma-i] = aux;
+ }
+ return 1;
+ }
+}
+
+void change_colums(int matrix[tam][tam], int lin, int colx, int coly){
+ int aux;
+ for (int i=0; i<lin; ++i){
+ aux = matrix[i][colx-1];
+ matrix[i][colx-1] = matrix[i][coly-1];
+ matrix[i][coly-1] = aux;
+ }
+}
+
+// matriz tamanha da coluna, linhas para trocar
+void change_lines(int matrix[tam][tam], int col, int linx, int liny){
+ int aux;
+ for (int i=0; i<col; ++i){
+ aux = matrix[linx-1][i];
+ matrix[linx-1][i] = matrix[liny-1][i];
+ matrix[liny-1][i] = aux;
+ }
+}
+
+void show_matrix( int matrix[tam][tam], int x, int y){
+ for( int i=0; i<x; ++i){
+ for( int j=0; j<y; ++j){
+ mvprintw(startY+altura+1+i, startX+xMax/2+1+5*j,"%d", matrix[i][j]);
+ refresh();
+ }
+ //printf("\n");
+ }
+}
+
+void matrixcpy(int matrixcpy[tam][tam], int matrix[tam][tam], int x, int y ){
+ for (int i=0; i<x; ++i){
+ for (int j=0; j<y; ++j){
+ matrixcpy[i][j] = matrix[i][j];
+ }
+ }
+}
+
+void create_matrix(int matrix[tam][tam], int x, int y){
+ for (int i=0; i<x; ++i){
+ for (int j=0; j<y; ++j){
+ mvprintw(startY+altura+1,startX+1, "Digite os numeros e pressione espaco ou enter:");
+ refresh();
+ scanf("%d", &matrix[i][j]);
+ mvprintw(startY+altura+2+i,startX+1+5*j,"%d", matrix[i][j]);
+ refresh();
+ }
+ }
+}
+
+void clear_matrixwin(int startY, int startX, int maxY, int maxX){
+ for(int i=startY+1; i<maxY; i++){
+ for(int j=startX+1; j<maxX-1; ++j){
+ mvprintw(i, j, " ");
+ }
+ }
+}
+
+void show_matrix_win2( int matrix[tam][tam], int x, int y){
+ for( int i=0; i<x; ++i){
+ for( int j=0; j<y; ++j){
+ mvprintw(startY+altura+2+i,startX+1+5*j,"%d", matrix[i][j]);
+ refresh();
+ }
+ //printf("\n");
+ }
+} \ No newline at end of file