Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- void somar_matrizes(int, int, int, int, int);
- int main(){
- int *M1, *M2, *M3, LINHAS, COLUNAS;
- int i, j, x;
- printf("Informe numero de linhas: ");
- scanf("%d", &LINHAS);
- printf("Informe o numero de colunas: ");
- scanf("%d", &COLUNAS);
- if(LINHAS > 0 && COLUNAS > 0){
- M1 = (int *) malloc (LINHAS*COLUNAS*sizeof(int));
- if(M1 == NULL){
- printf("Nao ha memoria disponivel.\n");
- return 0;
- }else{
- printf("\nM1[%dx%d]\n\n", LINHAS, COLUNAS);
- for(i = 0; i < LINHAS; i++){
- for(j = 0; j < COLUNAS; j++){
- printf("Informe M[%d][%d]: ", i, j);
- scanf("%d", M1 + i*COLUNAS+j);
- }
- }
- }
- printf("%d", M1 + i*COLUNAS+j);
- free(M1);
- M2 = (int *) malloc (LINHAS*COLUNAS*sizeof(int));
- if(M2 == NULL){
- printf("Nao ha memoria disponivel.\n");
- return 0;
- }else{
- printf("\nM2[%dx%d]\n\n", LINHAS, COLUNAS);
- for(i = 0; i < LINHAS; i++){
- for(j = 0; j < COLUNAS; j++){
- printf("Informe M[%d][%d]: ", i, j);
- scanf("%d", M2 + i*COLUNAS+j);
- }
- }
- }
- free(M2);
- }else{
- printf("Matriz nula [0x0]\n");
- return 0;
- }
- printf("\n\n");
- return 0;
- }
- void somar_matrizes(int *M1, int *M2, int *M3, int LINHAS, int COLUNAS){
- int i, j;
- for (i=0; i<LINHAS; i++)
- for (j=0; j<COLUNAS; j++)
- *(M3+(i*COLUNAS+j)) = *(M1+(i*COLUNAS+j))+*(M2+(i*COLUNAS+j));
- }
Advertisement
Add Comment
Please, Sign In to add comment