Commit b289039c by Jürgen Hein

Upload New File

parent a5a21f16
Showing with 70 additions and 0 deletions
//liida kaks maatriksit;
//liida kaks maatriksit;
//maatriksid peavad olema
//ühesuurused;
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define MAX 15
//int sisestaInt(char[], int);
void sisestaM_N(int*, int*);
void genereeriMaatriks(int,int n,int[][n]);
void liidaMaatriks(int, int n,int[][n],int[][n],int[][n]);
void valjastaMaatriks(char[],int,int n, int[][n]);
int main(void){
srand(time(NULL));
//int m = sisestaInt("m");
//int n = sisestaInt("n");
int m, n;
sisestaM_N(&m, &n);
int M1[m][n], M2[m][n], Sum[m][n];
genereeriMaatriks(m,n,M1);
genereeriMaatriks(m,n,M2);
liidaMaatriks(m,n,M1,M2,Sum);
valjastaMaatriks("Esimene liidetav:\n",m,n,M1);
valjastaMaatriks("Teine liidetav:\n",m,n,M2);
valjastaMaatriks("Summa:\n",m,n,Sum);
return 0;
}
void sisestaM_N(int* x, int* y){
printf("Sisesta maatriksite mõõtmed. (2...15)\n");
do{
printf("Read:");
scanf("%d", x);
printf("Tulbad:");
scanf("%d", y);
}while(*x>MAX ||*x<2||*y>MAX||*y<2);
}
void genereeriMaatriks(int x,int y,int M[][y]){
int i, j;
for (i = 0; i < x; i++)
{
for (j = 0; j < y; j++)
{
M[i][j]= rand()%100 + 1;
}
}
}
void liidaMaatriks(int x, int y,int M1[][y],int M2[][y],int S[][y]){
int i, j;
for (i = 0; i < x; i++)
{
for (j = 0; j < y; j++)
{
S[i][j] = M1[i][j] + M2[i][j];
}
}
}
void valjastaMaatriks(char teade[],int x,int y, int M[][y]){
int i, j;
printf("\n%s", teade);
for (i = 0; i < x; i++)
{
printf("\n");
for (j = 0; j < y; j++)
{
printf("%3d ", M[i][j]);
}
}
printf("\n");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment