Calculate the sum of squares

    0

    0

    The code in main() calculates the sum of the squares of integers from n to m.

    Library: skaf

    #include <iostream>
    using namespace std;
    
    int main() {
      int n, m;
      int sum = 0;
    
      cout << "Enter the value of n: ";
      cin >> n;
    
      cout << "Enter the value of m: ";
      cin >> m;
    
      for (int i = n; i <= m; i++) {
        sum += i * i;
      }
    
      cout << "The sum of the squares from " << n << " to " << m << " is " << sum << endl;
    
      return 0;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.