Advertisement
Guest User

przerobione

a guest
Feb 17th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main(){
  5.     int odleglosc, godziny1 ,minuty1 ,godziny2 ,minuty2;
  6.     int czas1, czas2, czas;
  7.  
  8.     printf("Podaj odlegosc\n");
  9.     scanf("%d", &odleglosc);
  10.     printf("Podaj godzine odjazdu\n");
  11.     scanf("%d:%d", &godziny1, &minuty1);
  12.     if(minuty1 >= 60){
  13.         minuty1 = minuty1%60; godziny1++;
  14.     }
  15.     if(godziny1 >= 24){
  16.         godziny1 = godziny1%24;
  17.     }
  18.     printf("Podaj godzine przyjazdu\n");
  19.     scanf("%d:%d", &godziny2, &minuty2);
  20.     if(minuty2>=60){
  21.         minuty2=minuty2%60; godziny2++;
  22.     }
  23.     if(godziny2 >= 24){
  24.         godziny2 = godziny2%24;
  25.     }  
  26.    
  27.     czas1 = godziny1 + (float)minuty1/60;
  28.     czas2 = godziny2 + (float)minuty2/60;
  29.    
  30.     if(czas2 <= czas1) {
  31.   czas = 24 - czas1 + czas2;
  32. }    else {
  33.      czas = czas2 - czas1;
  34.     }
  35.    
  36.         float szybkosc = (float)odleglosc/(float)czas;
  37.     printf("Potrzebna predkosc to %d km/h\n", (int)szybkosc);
  38.  
  39.    
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement