Guest User

Untitled

a guest
Feb 4th, 2015
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. רגיל 10 - כתוב פונקציה הקולטת סידרה לא מוגבלת של מספרים המסתיימת במספר 1 ומדפיסה את
  2. השניים הקטנים ביותר החיוביים, ניתן להניח כי יש כאלו.
  3. #include <stdio.h>
  4. void swap(int *a, int *b)
  5. {
  6. int temp = *a;
  7. *a = *b;
  8. *b = temp;
  9. }
  10. int main()
  11. {
  12. int n1, n2;
  13. scanf("%d%d",&n1, &n2);
  14. if (n1 > n2) swap(&n1, &n2);
  15. while(scanf("%d",&check) == 1 && check != -1)//למה משמשת שורת הקוד הזו?
  16. {
  17. if (check > 0)
  18. {
  19. if (n2 < 0) n2 = check;
  20. else if (n1 < 0) n1 = check;
  21. else if (check < n1)
  22. {
  23. n2 = n1;
  24. n1 = check;
  25. }
  26. else if (check < n2)
  27. {
  28. n2 = check;
  29. }}}
  30. printf("%d %d\n", n1, n2);
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment