Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- clear all
- suma=0;
- n=input('Podaj wartość n: ');
- while round(n)~=n
- n=input('Podana liczba n nie jest całkowita. Podaj ponownie wartość n: ');
- while n<0
- n=input('Podana liczba n jest ujemna. Podaj ponownie wartość n: ');
- end
- end
- while n<0
- n=input('Podana liczba n jest ujemna. Podaj ponownie wartość n: ');
- while round(n)~=n
- n=input('Podana liczba n nie jest całkowita. Podaj ponownie wartość n: ');
- end
- end
- for k=1:n
- if (2*k-1)>n
- break
- else
- suma=suma+(2*k-1);
- end
- end
- disp(['Suma=', num2str(suma)]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement