Commit afe04b92 by videid

hw2

parent 673ce6bd
9
Keskmine 9.98
Ronimine 3.10
Pikk 17.52
Lyhike 3.73
Rada2 6.19
Mets 4.92
Soo3 5.05
Lyhike2 3.81
Varemed 5.99
1
\ No newline at end of file
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef char string[31];
void size(int* rows,int* columns);
void fill(int rows,int columns);
int main(){
float tps;
int i;
int j=0;
int h = 0;
int f = 0;
int k = 0;
int g = 0;
char *b ;
char *c ;
string array[30] = {0};
char *name[15];
char *length[15];
FILE *my;
my = fopen("C:\\Users\\vggre\\Documents\\GitHub\\iax5832\\iax0583\\homework2\\081.txt","r");
for(i = 0; i < 30; i++){
fscanf(my, "%s", array[i]);
printf("%s\n",array[i]);
}
int main(void){
int rows ;
int columns ;
size(&rows,&columns);
fill(rows,columns);
fclose(my);
while (*array[h] != 0 ){
h=h+1;
}
printf("%d\n",h);
for(j = 1; j < h-1; j=j+2){
printf(" trail %d %s\n",((j+1)/2),array[j]);
}
return 0 ;
}
void size(int *rows,int *columns){
for(i = 1; i < h-1; i++){
*rows = 0;
*columns =0 ;
while(*rows<= 0) {
printf("enter number of rows\n");
scanf("%d", rows);
if (i%2){
b = array[i];
name[i/2] = b;
printf("%s\n",name[i/2]);
}
else {
c = array[i];
length[(i-1)/2] = c;
printf("%s\n",length[(i-1)/2]);
}
}
while(*columns <= 0) {
printf("enter number of columns\n");
scanf("%d", columns);
}
printf("%d rows %d columns \n",*rows,*columns);
}
void fill(int rows,int columns){
int h;
int i;
int j;
int myArray[rows][columns];
for (i=0 ;i< rows ;i++){
for(j=0;j<columns;j++){
printf("enter number \n");
scanf("%d", &h);
myArray[i][j] = h;
printf("\n\n\n\n\n\n\n");
char *temp;
for (k = 0; k < (h/2) -1; k++){
for (g = 0;g < (h/2)-2-k; g++ ){
if (*length[g] > *length[g+1]){
temp = length[g+1];
length[g+1] = length[g];
length[g] = temp;
temp = name[g+1];
name[g+1] = name[g];
name[g] = temp;
}
}
}
for(i = 0; i < (h/2) -1; i++){
printf("%s ",name[i]);
printf("%s km\n",length[i]);
}
for (i=0 ;i< rows ;i++){
for(j=0;j<columns;j++){
printf("%d",myArray[i][j]);
printf("enter time in minutes\n");
scanf("%f", &tps);
for(i = 0; i < (h/2) -1; i++){
char *y ;
y = length[i] ;
float time;
time = atof(y)/0.083; // this is not precise beyond minutes because that's not relevant for a hike
if (time<= tps){
printf ("the %s hike is doable is this time\n",name[i]);
}
}
printf("\n");
}
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