Commit 09f0e942 by karlki

suusahüpped hindamine

parent 6830b2fa
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
srand(time(NULL));
int n;
int j;
int i = 0;
int sum;
int swap = 0;
int k;
int h;
do {
printf("n: ");
scanf("%d", &n);
} while(n < 2);
int H[n][5];
float A[n];
for (i = 0;i<n;i++) {
for (j=0; j<5;j++) {
H[i][j] = rand() % 5;
printf("%d. tulba %d. liige on %d\n",i+1, j+1, H[i][j]);
}
printf("\n");
}
j = 0;
i = 0;
printf("sorted lists\n");
for (;i<n;i++) {
for( k = 0; k < 4; k++) {
for( h = 0; h < 4 - k;h++) {
if (H[i][h] > H[i][h+1]) {
swap = H[i][h];
H[i][h] = H[i][h+1];
H[i][h+1] = swap;
}
}
}
}
for (i = 0; i<n;i++) {
for (j= 0; j<5;j++) {
printf("%d. tulp %d. liige on %d\n",i+1,j+1,H[i][j]);
}
printf("\n");
}
for (i = 0; i<n;i++) {
sum = 0;
for (j = 1;j<4;j++) {
sum = sum + H[i][j];
}
A[i] = (double) sum/3;
}
for (i = 0;i<n;i++) {
printf("%d. keskv22rtus on %f\n", i+1, A[i]);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
srand(time(NULL));
int n;
int j;
int i = 0;
int sum;
int swap = 0;
int k;
int h;
do {
printf("n: ");
scanf("%d", &n);
} while(n < 2);
int H[n][5];
float A[n];
for (i = 0;i<n;i++) {
for (j=0; j<5;j++) {
H[i][j] = rand() % 5;
printf("%d. tulba %d. liige on %d\n",i+1, j+1, H[i][j]);
}
printf("\n");
}
j = 0;
i = 0;
printf("sorted lists\n");
for (;i<n;i++) {
for( k = 0; k < 4; k++) {
for( h = 0; h < 4 - k;h++) {
if (H[i][h] > H[i][h+1]) {
swap = H[i][h];
H[i][h] = H[i][h+1];
H[i][h+1] = swap;
}
}
}
}
for (i = 0; i<n;i++) {
for (j= 0; j<5;j++) {
printf("%d. tulp %d. liige on %d\n",i+1,j+1,H[i][j]);
}
printf("\n");
}
for (i = 0; i<n;i++) {
sum = 0;
for (j = 1;j<4;j++) {
sum = sum + H[i][j];
}
A[i] = (double) sum/3;
}
for (i = 0;i<n;i++) {
printf("%d. keskv22rtus on %f\n", i+1, A[i]);
}
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