fork download
  1. #include <stdio.h>
  2. int main()
  3. {
  4. int a, b;
  5. printf("Podaj dwie liczby calkowite wieksze od 0:\n");
  6. printf("a = ");
  7. scanf("%i", &a);
  8. printf("b = ");
  9. scanf("%i", &b);
  10. if (a <= 0 | b <= 0) {
  11. printf("Podano nieprawidlowe wartosci.");
  12. }
  13. else {
  14. printf("NWD(%i,%i)=", a, b);
  15. }
  16. for (;a != b;) {
  17. if (a > b) {
  18. a = a - b;
  19. }
  20. else {
  21. b = b - a;
  22. }
  23. }
  24. printf("%i\n", a);
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 4384KB
stdin
12
4
stdout
Podaj dwie liczby calkowite wieksze od 0:
a = b = NWD(12,4)=4