1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rina8888 [55]
4 years ago
9

"Find the sum of the squares of the integers from 1 to MySquare, where MySquare is input by the user. Be sure to check that the

user enters a positive integer"
Computers and Technology
1 answer:
luda_lava [24]4 years ago
5 0
Please be aware that for the best performance, you shouldn't try to calculate the sum manually. Instead it's better to use a formula like n(n+1)(2n+1)/6, where n is the number input by the user. (this is a formula to calculate the sum of the first n squares: it's a famous formula).
But here is a program (in C) to do it manually:

#include
int sumSquares(int n) {
if(n == 0) return 0;
else if (n == 1) return 1;
else return (n*n) + sumSquares(n - 1);
}
int main() {
int mySquare;
puts("Enter mySquare");
scanf("%d", &mySquare);
if(mySquare < 0) mySquare *= -1;
// makes it positive if it was negative
printf("Sum of squares: %d", sumSquares(mySquare));
}
You might be interested in
When does patch 1.6 come out for the division?
Fynjy0 [20]
Thurdsay the 9th of february 
5 0
3 years ago
What Will Social Media Look Like in the Future?
Nutka1998 [239]

Answer: Social Media has come long way from just being a platform for interaction to necessity entity. In today's era social media plays a vital part and it can be stated that it'll continue to have the same effect in the future. From being a platform for business organizations to endorse their product and services to a wider audience, to being a platform for an individual to connect to his/her friend and family that live all the way on the other end of the world.

There are several possibilities that Social Media can unlock in the possible future.

3 0
4 years ago
Ben has to write a note on color concepts. Help him complete the following sentences.
k0ka [10]
<span>Ben has to write a note on color concepts. Help him complete the following sentences.
When light hits a surface, the surface absorbs some of the light and reflects the rest. The color that you see depends on which light waves the surface reflects
( reflects, absorbs, emits) the most. You perceive objects as having a specific color because of these constituent ______( rays, colors, intensities) of light.

I wasn't sure on the last one.</span>
5 0
4 years ago
Read 2 more answers
Mr. Olgesandravich is proctoring students working at their own pace in an online class. He is generating a spreadsheet that show
strojnjashka [21]
The answer to the given question above would be option A. Based on the given scenario above, the two formats that Mr. Olgesandravich is most likely using is <span>Percentages and date. Hope this is the answer that you are looking for. Have a great day ahead!</span>
6 0
4 years ago
Read 2 more answers
p3_unzip :: [(a,b)] -&gt; ([a], [b]) Write a function that takes a list of two-tuples and returns a tuple of two lists -- the fi
klio [65]

Answer:

<em>C++.</em>

Explanation:

#include <iostream>

#include<tuple>

using namespace std;

////////////////////////////////////////////////////////////

tuple<char*, int*> p3_unzip(tuple<char, int>* list, int count) {

   char* list1 = new char[count];

   int* list2 = new int[count];

   

   for (int i=0; i<count; i++) {

       tuple<char, int> temp = list[i];

       list1[i] = get<0>(temp);

       list2[i] = get<1>(temp);

   }

   

   tuple<char*, int*> new_tuple;

   get<0>(new_tuple) = list1;

   get<1>(new_tuple) = list2;

   

   return new_tuple;

}

int main() {

   tuple<char, int>* list;

   int count = 0;

   ////////////////////////////////////////

   cout<<"How many tuples? ";

   cin>>count;

   list = new tuple<char, int>[count];

   cout<<endl;

   

   char a;

   int b;

   tuple<char, int> temp;

   for (int i=0; i<count; i++) {

       cout<<"tuple "<<i+1<<" char: ";

       cin>>a;

       get<0>(temp) = a;

       

       cout<<"tuple "<<i+1<<" int: ";

       cin>>b;

       get<1>(temp) = b;

       

       list[i] = temp;

       cout<<endl;

   }

   ////////////////////////////////////////

   tuple<char*, int*> new_tuple = p3_unzip(list, count);

   char* list1 =  get<0>(new_tuple);

   int* list2 = get<1>(new_tuple);

   

   cout<<"Returned tuple:([";

   for (int i=0; i<count-1; i++) {

       cout<<list1[i]<<", ";

   }

   

   cout<<list1[count-1]<<"],[";

   

   for (int i=0; i<count-1; i++) {

       cout<<list2[i]<<", ";

   }

   

   cout<<list2[count-1]<<"])";

   ////////////////////////////////////////

   delete[] list, list1, list2;

   return 0;

}

4 0
4 years ago
Other questions:
  • How does FTP work? explain in brief.
    8·1 answer
  • A _______ is a piece of computer hardware used for the modulation and demodulation of data between digital and analog formats.
    10·1 answer
  • Draw a flowchart and write pseudocode to represent the logic of a program that allows the user to enter values for the width and
    15·1 answer
  • Problems and Exercises 16 through 43 are based on the entire ("big" version) Pine Valley Furniture Company database. Note: Depen
    13·1 answer
  • In spreadsheet programs, labels and constant values are always copied exactly to the new location; what happens to formulas when
    10·1 answer
  • B. What is a window?​
    8·2 answers
  • Plz answer me will mark as brainliest​
    8·1 answer
  • Select the correct answer.
    11·1 answer
  • A malicious user in your organization was able to use the Trinity Rescue Kit to change the password on a department manager's co
    7·1 answer
  • True or false. A plug-in card is always required to support pc sound
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!