Advertisement
edems96

Prog1 4. kisZH Euró

Oct 26th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef struct Penz {
  4.     int euro, cent;
  5. } Penz;
  6.  
  7. Penz beolvas() {
  8.     Penz p;
  9.    
  10.     scanf("%d %d", &p.euro, &p.cent);
  11.     getchar(); // read enter
  12.    
  13.     return p;
  14. }
  15.  
  16. Penz osszead(Penz a, Penz b) {
  17.     Penz c;
  18.     c.euro = a.euro + b.euro + ((a.cent + b.cent) / 100);
  19.     c.cent = (a.cent + b.cent) % 100;
  20.    
  21.     return c;
  22. }
  23.  
  24. Penz kerekit(Penz p) {
  25.     if( p.cent >= 50 )
  26.         p.euro++;
  27.  
  28.     p.cent = 0;
  29.    
  30.     return p;
  31. }
  32.  
  33. int main(void) {
  34.     Penz a = beolvas();
  35.     Penz b = kerekit(osszead(a, a));
  36.    
  37.     printf("%deuro %dc\n", b.euro, b.cent);
  38.    
  39.     /*Penz a = beolvas();
  40.     Penz b = kerekit(a);
  41.     Penz c = osszead(a, a);
  42.    
  43.     printf("%deuro %dc\n", a.euro, a.cent);
  44.     printf("%deuro %dc\n", b.euro, b.cent);
  45.     printf("%deuro %dc\n", c.euro, c.cent); */
  46.    
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement