+ 4

Help c++

you need to find the sum of the squares of all integers from A to B (you can only use FOR)

7th Mar 2018, 3:05 PM
Borker The Worker
Borker The Worker - avatar
7 Answers
+ 5
int n = 0, i = 0; cin>>i; // enter A and B cin>>n; int sum = 0; for(; i <= n; i++) { sum += i*i; } cout<< sum;
7th Mar 2018, 3:12 PM
Paul
+ 10
[b.(b+1).(2b+1) - a. (a+1). (2a+1)]/6 //1 liner //using basic maths
7th Mar 2018, 3:25 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
if anything is not clear, just ask and i ll try to make it clear for ya
7th Mar 2018, 3:24 PM
Paul
+ 2
#include<iostream> struct Main { long long a,b,c,d; Main() { std::cin>>a>>b; c=a-(a-b)*(b<a); d=a+(b-a)*(b>a); std::cout<<d*-~d*-~(d<<1)-c*~-c*~-(c<<1); } }MAIN; int main() { for(;;) return 0; }
16th Apr 2018, 8:30 PM
刘宇轩,一个来自西安的喜欢取长昵称的大学生。
刘宇轩,一个来自西安的喜欢取长昵称的大学生。 - avatar
+ 1
ty
7th Mar 2018, 3:25 PM
Borker The Worker
Borker The Worker - avatar
+ 1
corrected
7th Mar 2018, 3:35 PM
Paul