Commit ac47012f by raliis

Upload New File

parent 32462ccf
Showing with 88 additions and 0 deletions
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
srand(time(NULL)); // genereerib suvalise arvu seemne aja järgi
int N; // massiivi tulpade arv
int i, j, k; // loendurid
int l = 3; // lisaloendur laius
int temp; // ajutine muutuja
int randSize = 5;
float keskmine;
//N sisestamine
printf("Sisesta tabeli tulpade arv N: \n");
scanf("%d", &N);
// N kontroll
while(N <= 0 || N > 15)
{
printf("N peab olema vähemalt 1 ja väiksem kui 15, "
"sisesta uus N: \n");
scanf("%d", &N);
printf(" \n");
}
int H[N][5]; // hinnete massiivi deklareerimine
//suvaliste arvude genereerimine
for (i=0; i < N; i++)
{
for (j=0; j<5; j++)
{
H[i][j] = rand()% randSize;
printf("%d", H[i][j]);
}
printf("\n");
}
printf(" \n");
//sortimine
for (k=0; k<N; k++)
{
for (i=0; i<N; i++)
{
for (j=0; j<4; j++)
{
if (H[i][j] > H[i][j+1])
{
temp = H[i][j];
H[i][j] = H[i][j+1];
H[i][j+1] = temp;
}
}
}
}
//sorditud arvude printimine
for (i=0; i < N; i++)
{
for (j=0; j<5; j++)
{
printf("%d", H[i][j]);
}
printf("\n");
}
printf(" \n");
//keskmiste väärtuste arvutamine
for (i=0; i<N; i++)
{
keskmine = H[i][1] + H[i][2] + H[i][3];
keskmine = keskmine / 3;
printf("%d rea keskmine on: %.3f\n", i, keskmine);
}
return 0;
}
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