Commit 9e32c10d by Jürgen Hein

Upload New File

parent 3fe12f06
Showing with 93 additions and 0 deletions
/* Teostada rea ja massiivi elementide vahetuse.
/* Teostada rea ja massiivi elementide vahetuse.
* Kahe alamfunktsioonina: väljatrükk massiivist
* ja vahetavatest vektoritest.*/
#include <stdio.h>
//Prototüübid
int loe(char [], int, int);
void lugemineMaatr(char [], int k, int[k][k]);
void vahetus(char[], int n, int, int, int[][n], int[], int[]);
void trykkMaatriks(char[],int k, int[][k]);
void trykkVektor(char[], int, int[]);
int main(void)
{
int n,r,v;
int min = 0, max = 10;
n=loe("maatriksi mõõde:", min, max);
int M[n][n], R[n], V[n];
lugemineMaatr("algab maatriksi elementide sisestus", n, M);
r = loe("Rea number",n, min);
v = loe("Veeru number",n, min);
vahetus("algab vahetus",n,r,v,M,R,V);
trykkMaatriks("maatriksi ise", n, M);
trykkVektor("Rea trükk", n, R); //Saame mitu korda kasutada ühte funktsiooni
trykkVektor("Veeru trükk", n, V);
return 0;
}
int loe(char teade[], int min, int max)
{
int arv;
printf("%s\n", teade);
do
{
printf("Sisesta arv vahemikus %d...%d\n",min,max);
scanf("%d",&arv);
} while(arv < min || arv > max);
return arv;
}
void lugemineMaatr(char teade[], int k, int maatriks[][k])
{
int i, j;
printf("\n%s\n",teade);
for (i = 0; i < k; i++)
{
for (j = 0; j < k; j++)
{
printf("Element kohal %d, %d", i,j);
scanf("%d",&maatriks[i][j]);
}
}
}
void vahetus(char teade[], int n, int x, int y, int m[][n], int X[], int Y[])
{
int i;
printf("\n%s",teade);
for (i = 0; i < n; i++)
{
X[i] = m[i][x];
Y[i] = m[y][i];
m[i][x]=Y[i];
m[y][i]=X[i];
}
}
void trykkMaatriks(char teade[],int n, int maatriks[][n])
{
int i, j;
printf("%s\n",teade);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%d", maatriks[i][j]);
}
}
}
void trykkVektor(char teade[], int n, int m[])
{
int i;
printf("%s\n", teade);
for(i=0;i<n;i++)
{
printf("%d",m[i]);
}
}
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