Advertisement
Guest User

Suma NWD

a guest
Nov 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int a,b,c,i,maksimum=1000000000,snwd=0,nwd=0,x=0,y=0,ostatni;
  5. scanf("%i %i %i", &a, &b, &c);
  6. for (i=1;i=maksimum;i++)
  7. {
  8. if (c==1)
  9. {
  10. {
  11. if (a==1 || b==1)
  12. {
  13. snwd=snwd+ostatni;
  14. }
  15. else
  16. {
  17. x=a;
  18. y=b;
  19. nwd=x%y;
  20. while (nwd!=0)
  21. {
  22. x=y;
  23. y=nwd;
  24. nwd=x%y;
  25. }
  26. ostatni=y;
  27. snwd=snwd+y;
  28. }
  29. }
  30. scanf("%i", &c);
  31. }
  32. else if (c>1)
  33. {
  34. a=b;
  35. b=c;
  36. scanf("%i", &c);
  37. }
  38. else if (c==0)
  39. {
  40. break;
  41. }
  42. }
  43. printf("%i", snwd);
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement