#335
Să se scrie un program care citește numărul natural n și determină suma S=1*2-2*3+3*4-...±n*(n+1).
| Problema | Expresie3 | Operații I/O |
tastatură/ecran
|
|---|---|---|---|
| Limita timp | 0.1 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #63639326 | Utilizator | |
| Fișier | expresie3.cpp | Dimensiune | 218 B |
| Data încărcării | 12 Martie 2026, 11:06 | Scor/rezultat | Eroare de compilare |
expresie3.cpp: In function 'int main()': expresie3.cpp:8:15: error: lvalue required as left operand of assignment if(i%2=0) { cout<<s=s-i*(i+1); ^ expresie3.cpp:8:28: error: no match for 'operator=' (operand types are 'std::basic_ostream<char>' and 'int') if(i%2=0) { cout<<s=s-i*(i+1); ^ expresie3.cpp:8:28: note: candidate is: In file included from /usr/include/c++/4.8/iostream:39:0, from expresie3.cpp:1: /usr/include/c++/4.8/ostream:58:11: note: std::basic_ostream<char>& std::basic_ostream<char>::operator=(const std::basic_ostream<char>&) <deleted> class basic_ostream : virtual public basic_ios<_CharT, _Traits> ^ /usr/include/c++/4.8/ostream:58:11: note: no known conversion for argument 1 from 'int' to 'const std::basic_ostream<char>&' expresie3.cpp:9:9: error: expected '}' before 'else' else cout<<s=s+i*(i+1); } ^ expresie3.cpp:9:21: error: no match for 'operator=' (operand types are 'std::basic_ostream<char>' and 'int') else cout<<s=s+i*(i+1); } ^ expresie3.cpp:9:21: note: candidate is: In file included from /usr/include/c++/4.8/iostream:39:0, from expresie3.cpp:1: /usr/include/c++/4.8/ostream:58:11: note: std::basic_ostream<char>& std::basic_ostream<char>::operator=(const std::basic_ostream<char>&) <deleted> class basic_ostream : virtual public basic_ios<_CharT, _Traits> ^ /usr/include/c++/4.8/ostream:58:11: note: no known conversion for argument 1 from 'int' to 'const std::basic_ostream<char>&' expresie3.cpp: At global scope: expresie3.cpp:10:5: error: 'cout' does not name a type cout<<"Rezultatul este "<<s; ^ expresie3.cpp:11:1: error: expected declaration before '}' token } ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Expresie3 face parte din prima categorie. Soluția propusă de tine va fi evaluată astfel:
Suma punctajelor acordate pe testele utilizate pentru verificare este 100. Astfel, soluția ta poate obține cel mult 100 de puncte, caz în care se poate considera corectă.