Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define D 10
- int main()
- {
- int m1, n1, m2, n2, i, j, k;
- int a[D][D];
- int b[D][D];
- int vek_pro[D][D];
- do {
- do {
- printf("Unesi dimenzije prve matrice : ");
- scanf("%d %d", &m1, &n1);
- }
- while ((m1<1 || m1>10) || (n1<1 || n1>10));
- do {
- printf("Unesi dimenzije druge matrice : ");
- scanf("%d %d", &m2, &n2);
- }
- while ((m2<1 || m2>10) || (n2<1 || n2>10));
- }
- while (m1!=n2 || m2!=n1);
- printf("\nUnesi elemente prve matrice");
- for (i=0; i<m1; i++)
- for (j=0; j<n1; j++) {
- printf("\na[%d, %d] ", i+1, j+1);
- scanf("%d", &a[i][j]);
- }
- printf("\nUnesi elemente druge matrice");
- for (i=0; i<m2; i++)
- for (j=0; j<n2; j++) {
- printf("\nb[%d, %d] ", i+1, j+1);
- scanf("%d", &b[i][j]);
- }
- printf("\nOriginalna prva matrica:\n");
- for (i=0; i<m1; i++) {
- for (j=0; j<n1; j++) {
- printf("%d ", a[i][j]);
- }
- printf("\n");
- }
- printf("\nOriginalna druga matrica:\n");
- for (i=0; i<m2; i++) {
- for (j=0; j<n2; j++) {
- printf("%d ", b[i][j]);
- }
- printf("\n");
- }
- for (i=0; i<m1; i++) {
- for (k=0; k<n2; k++)
- vek_pro[i][k]=0;
- }
- for (i=0; i<m1; i++) {
- for (j=0; j<n1; j++) {
- for (k=0; k<n2; k++)
- vek_pro[i][k]+=a[i][j]*b[j][k];
- }
- }
- printf("\nIzmnozena matrica:\n");
- for (i=0; i<m1; i++) {
- for (j=0; j<n2; j++)
- printf("%d ", vek_pro[i][j]);
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement