|
|
вернуться в форумWhere is my mistake?Tell me please.C++. #include <iostream.h> main() {int n,i,s=0; cin>>n; if(n==0)cout<<1; else for(i=1;i<=n;i++)s+=i; cout<<s<<endl; return 0;} Your mistake is that n may be negative Re: Where is my mistake?Tell me please.C++. Послано ARCH 26 янв 2009 23:00 Artur jan error is that цыфры могут быть отрицательными тоже :) Here is on Pascal :) var n,s:longint; begin readln (n); s:=0; if n=0 then s:=1; if n>=0 then while n<>0 do begin s:=s+n; n:=n-1; end; if n<0 then while n<>2 do begin s:=s+n; n:=n+1; end; WriteLn(s); end. |
|
|