#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <locale.h>
int main()
{
setlocale(LC_ALL, "Portuguese");
int N = 2, M = 2, x;
int mat[N][M];
srand(time(NULL));
printf(" - MATRIZ - \n");
for (int i = 0; i < N; i++){
for (int j = 0; j < M; j++){
mat[i][j] = rand()%100;
printf("%6d", mat[i][j]);
}
printf("\n");
}
printf("\n\n");
printf("Digite um valor: ");
scanf("%d", &x);
printf("\n");
for (int i = 0; i < N; i++){
for (int j = 0; j < M; j++){
if (x==mat[i][j]){
printf("O valor %d está na matriz na posição [%d][%d]", x, i, j);
}
}
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main()
{
setlocale(LC_ALL, "Portuguese");
int N, mat[N][N], SomaL = 0, SomaC = 0, SomaD = 0;
printf("Digite o valor do tamanho das linhas e colunas da matriz: ");
scanf("%d", &N);
printf("\n");
for (int i = 0; i < N; i++){
for (int j = 0; j < N; j++){
printf("Digite o valor de [%d][%d] ", i, j);
scanf("%d", &mat[i][j]);
if (i==0){
SomaL += mat[i][j];
}
if (j==0){
SomaC += mat[i][j];
}
if (i==j){
SomaD += mat[i][j];
}
}
}
printf("\n\n");
if ((SomaL==SomaC)&&(SomaC==SomaD)){
printf("A matriz é um quadrado mágico!\n");
} else {
printf("A matriz não é um quadrado mágico!\n");
}
return 0;
}
#include <stdio.h>
#define MAX 5 // Atribuição desnecessária, pois as dimensões das matrizes vão ser determinadas pelo usuário
int main(){
int m, n, nb, p, i, j, k;
float A[MAX][MAX], B[MAX][MAX], C[MAX][MAX];
printf("Digite as dimensoes (mxn) da matriz A: ");
scanf("%d", &m); scanf("%d", &n);
printf("Digite a Matriz A:\n");
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
scanf("%f", &A[i][j]);
printf("Digite as dimensoes (nxp) da matriz B: ");
scanf("%d", &nb); scanf("%d", &p);
if (nb != n)
printf("Parametros incorretos! Nao eh possivel calcular!");
else{
printf("Digite a matriz B:\n");
for(i = 0; i < n; i++)
for(j = 0; j < p; j++)
scanf("%f", &B[i][j]);
for (i = 0; i < m; i++)
for (j = 0; j <p; j++){
C[i][j] = 0;
for (k= 0; k <n; k++)
C[i][j] = C[i][j] + A[i][k] * B[k][j];
}
printf("Matriz A X B:\n");
for (i = 0; i < m; i++){
for (j = 0; j< p; j++)
printf("%.2f", C[i][j]);
printf("\n");
}
}
return 0;
}