Create a C program that uses a for loop to sum up the square

Create a C++ program that uses a \"for\" loop to sum up the squares of the integer from 1 through 10. Create a C++ program that uses a \"for\" loop to display the number 1- 5 and their squares.

Solution

// C++ code to sum up the squares of the integers from 1 through 10
#include <iostream>

using namespace std;

int main()
{
int squareSum = 0;
for (int number = 1; number < 10; ++number)
{
    squareSum = squareSum + (number*number);
}

cout << \"Sum of squares of integers from 1 through 10: \" << squareSum << endl;

return 0;
}

/*
output:
Sum of squares of integers from 1 to 10: 285

*/


//C++ code display number and its square from 1 to 5
#include <iostream>

using namespace std;

int main()
{
   cout << \"Number\\tSquare\ \";
   for (int number = 1; number <= 5; ++number)
   {
     cout << number << \"\\t\" << (number*number) << endl;
   }
   return 0;
}

/*
output:

Number Square
1         1
2         4
3         9
4         16
5         25

*/

 Create a C++ program that uses a \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site