Advertisement
warcislawtez

Untitled

Feb 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. clc
  2. clear all
  3. suma=0;
  4. n=input('Podaj wartość n: ');
  5. while round(n)~=n
  6. n=input('Podana liczba n nie jest całkowita. Podaj ponownie wartość n: ');
  7. while n<0
  8. n=input('Podana liczba n jest ujemna. Podaj ponownie wartość n: ');
  9. end
  10. end
  11. while n<0
  12. n=input('Podana liczba n jest ujemna. Podaj ponownie wartość n: ');
  13. while round(n)~=n
  14. n=input('Podana liczba n nie jest całkowita. Podaj ponownie wartość n: ');
  15. end
  16. end
  17. for k=1:n
  18. if (2*k-1)>n
  19. break
  20. else
  21. suma=suma+(2*k-1);
  22. end
  23. end
  24. disp(['Suma=', num2str(suma)]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement