C++ Code that uses a for loop to compute and print the sum of the squares of a number obtained from the operator.
#include<iostream>
using namespace std;
int main()
/*
QUESTION: Write a C++ program that uses a for loop to compute and print
the sum of the squares of a number obtained from the operator.
For example if 5 is input, it will print 55 (i.e 1^2 + 2^2 + 3^2 + 4^2 + 5^2)
BY: OYENIRAN OLUWASHINA AKINLOYE
*/
{
// variable decleartion
int v,x,sax = 0;
cout<<"TYPE IN THE NUMBER"<<endl;
cin>> v;
//the initail value of x is set to 1 while the increment was also set to 1
for(x=1;x<=v;x++)
{
sax += x*x;
//the result of each square are presented and the total was shown at the last line of the results.
cout<<"THE RESULT IS: "<< sax<<endl;
}
return 0;
}
using namespace std;
int main()
/*
QUESTION: Write a C++ program that uses a for loop to compute and print
the sum of the squares of a number obtained from the operator.
For example if 5 is input, it will print 55 (i.e 1^2 + 2^2 + 3^2 + 4^2 + 5^2)
BY: OYENIRAN OLUWASHINA AKINLOYE
*/
{
// variable decleartion
int v,x,sax = 0;
cout<<"TYPE IN THE NUMBER"<<endl;
cin>> v;
//the initail value of x is set to 1 while the increment was also set to 1
for(x=1;x<=v;x++)
{
sax += x*x;
//the result of each square are presented and the total was shown at the last line of the results.
cout<<"THE RESULT IS: "<< sax<<endl;
}
return 0;
}
Comments
Post a Comment
Thanks for your comments.