Quellcode
- /* MATRIX * VEKTOR */
- /* Matrizenmultiplikation */
- #include <stdio.h>
- #include <stdlib.h>
- void einlesen(unsigned *a, unsigned n);
- void ausgabe(unsigned *y, unsigned n);
- double mult(unsigned *a, unsigned *x,unsigned *y, unsigned n);
- void Vekein(unsigned *x, unsigned n);
- int main()
- {
- unsigned *a, *x, *y; /* Zeiger auf Matrizen */
- unsigned n; /* Anzahl der Zeilen/Spalten */
- printf("Anzahl der Zeilen/Spalten: ");
- scanf("%d", &n);
- a = (unsigned *) calloc (n*n, sizeof(unsigned));
- x = (unsigned *) calloc (n*n, sizeof(unsigned));
- y = (unsigned *) calloc (n*n, sizeof(unsigned));
- printf("Erste Matrix einlesen\n");
- einlesen(a,n);
- printf("\nVektor einlesen\n");
- Vekein(x,n);
- mult(a, x,y, n);
- ausgabe (y,n);
- free(a);
- free(x);
- free(y);
- return 0;
- }
- void einlesen(unsigned *a, unsigned n)
- { int i,j;
- for (i=0; i<n; i++)
- {
- for (j=0; j<n; j++)
- scanf("%u", a+i*n+j); // i Zeile , j Spl.
- }
- }
- void Vekein(unsigned *x, unsigned n)
- { int i;
- for (i=0; i<n; i++)
- scanf("%u", &x[i]);
- }
- double mult(unsigned *a, unsigned *x, unsigned *y, unsigned n)
- { unsigned i, j, k;
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- { y[i] = 0;
- for (k = 0; k < n; k++)
- y[i] += *(a+i*n+k) * x[k];
- }
- return y[i];
- }
- void ausgabe(unsigned *y, unsigned n)
- {
- unsigned i;
- printf("\nErgebnis:\n");
- for (i=0;i<n;i++)
- printf("\n %u \n", y[i]);
- }
#######################################################################################################################
Quellcode
- /* Matrix * Matrix = Vektor.
- #include <stdio.h>
- #include <stdlib.h>
- void einlesen(unsigned *a, unsigned n);
- void ausgabe(unsigned *a, unsigned n);
- void mult(unsigned *a, unsigned *b, unsigned
- *c, unsigned n);
- /* Cpp */
- #include "global.h"
- void einlesen(unsigned *a, unsigned n)
- { int i,j;
- for (i=0; i<n; i++)
- {
- for (j=0; j<n; j++)
- scanf("%d", a+i*n+j);
- }
- }
- void ausgabe(unsigned *a, unsigned n)
- { unsigned i, j;
- for (i = 0; i < n; i++)
- { for (j = 0; j < n ; j++)
- printf("%u ", *(a+i*n+j));
- printf("\n");
- }
- // printf("\n");
- }
- void mult(unsigned *a, unsigned *b, unsigned
- *c, unsigned n)
- /* Multipiziert a mit b; Ergebnis in c
- */
- { unsigned i, j, k;
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- {
- *(c+i*n+j) = 0;
- for (k = 0;
- k < n; k++)
- *(c+i*n+j) += *(a+i*n+k) * *(b+k*n+j); }
- }
- */ main.cpp*/
- #include "global.h"
- int main()
- {
- unsigned *a, *b, *c;
- /* Zeiger auf Matrizen */
- unsigned n;
- /* Anzahl der Zeilen/Spalten */
- printf("Anzahl der Zeilen/Spalten: ");
- scanf("%u", &n);
- a = (unsigned *) calloc (n*n, sizeof(unsigned));
- b = (unsigned *) calloc (n*n, sizeof(unsigned));
- c = (unsigned *) calloc (n*n, sizeof(unsigned));
- printf("Erste Matrix einlesen\n");
- einlesen(a,n);
- printf("\nZweite Matrix einlesen\n");
- einlesen(b,n);
- mult(a, b,
- c, n);
- printf("\nErgebnismatrix:\n");
- ausgabe(c,
- n);
- free(a);
- free(b);
- free(c);
- getchar();
- getchar();
- }
- Normal
- 0
- 21
- false
- false
- false
- DE
- X-NONE
- X-NONE
######################################################################################################################
Quellcode
- /* Matrizenmultiplikation Matrix * Zahl */
- #include <stdio.h>
- #include <stdlib.h>
- void einlesen(unsigned *a, unsigned n);
- void ausgabe(unsigned *a, unsigned n);
- void mult(unsigned *a, unsigned *e,double z, unsigned n);
- int main()
- {
- unsigned *a,*e; /* Zeiger auf Matrizen */
- unsigned n; /* Anzahl der Zeilen/Spalten */
- double z;
- printf("Anzahl der Zeilen/Spalten: ");
- scanf("%u", &n);
- a = (unsigned *) calloc (n*n, sizeof(unsigned));
- e = (unsigned *) calloc (n*n, sizeof(unsigned));
- printf("Matrix einlesen\n");
- einlesen(a,n);
- printf("Geben Sie ein Vergroesserungsfaktor ein: "); // die Zahl
- scanf("%lf", &z);
- mult(a, e,z, n);
- printf("\nErgebnismatrix:\n");
- ausgabe(e, n);
- free(a);
- free(e);
- return 0;
- }
- void einlesen(unsigned *a, unsigned n)
- { int i,j;
- for (i=0; i<n; i++)
- {
- for (j=0; j<n; j++)
- scanf("%d", a+i*n+j);
- }
- }
- void ausgabe(unsigned *a, unsigned n)// Das musst du auswendig.
- { unsigned i, j;
- for (i = 0; i < n; i++)
- { for (j = 0; j < n ; j++)
- printf("%u ", *(a+i*n+j));
- printf("\n");
- }
- printf("\n");
- }
- void mult(unsigned *a, unsigned *e, double z, unsigned n)
- { unsigned i, j;
- for (i = 0; i < n; i++)
- for (j = 0; j < n; j++)
- { *(e+i*n+j) = 0;
- *(e+i*n+j) = *(a+i*n+j) * z;
- }
- }