• API
• FAQ
• Tools
• Archive
daily pastebin goal
75%
SHARE
TWEET

# Untitled

a guest Oct 21st, 2017 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <stdio.h>
2. #include <stdlib.h>
3. #include<time.h>
4.
5. const int L, C;
6. void preencher(int *p1, int *p2){
7.     int i,j;
8.     i=j=0;
9.     for(;i<L;i++){
10.         for(j = 0;j<C;j++){
11.             *((p1+i*C) + j)=(rand()%10)+1;
12.             *((p2+i*C)+j)=(rand()%10)+1;
13.         }
14.     }
15. }
16.
17. void somaMatriz(int *result, int *matriz1, int *matriz2){
18.     int i,j;
19.     i=j=0;
20.     for(;i<L;i++){
21.         for(j = 0;j<C;j++){
22.             *((result+i*C) + j) = *((matriz1+i*C) + j) + *((matriz2+i*C) + j);
23.         }
24.     }
25. }
26. void mostrar(int *matriz){
27.     int i,j;
28.     i=j=0;
29.     for(;i<L;i++){
30.         for(j = 0;j<C;j++){
31.             printf("A matriz[%i][%i] = %i \n",i,j,*((matriz+i*C) + j));
32.         }
33.     }
34. }
35. int main()
36. {
37.     printf("Digites os valores de linha e coluna da matriz\n");
38.     printf("Linha: ");
39.     scanf("%i",&L);
40.     printf("Coluna: ");
41.     scanf("%i",&C);
42.     int m1[L][C],m2[L][C],result[L][C];
43.
44.     srand(time(NULL));
45.     preencher((int *)m1, (int *)m2);
46.     somaMatriz((int *)result, (int *)m1, (int *)m2);
47.     mostrar(((int *)result);
48.
49.     return 0;
50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top