C++ Code that uses a do..while 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 do..while 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 0 instead of 1 because if 1 is used, the result will be decreased by 1
// using 0 value will by default set 1 as the intial value although 0 will be printed as the first value
x=0;
do
{
//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;
x++;
sax += x * x;
}
while (x<=v);
return 0;
}
using namespace std;
int main()
/*
QUESTION:Write a C++ program that uses a do..while 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 0 instead of 1 because if 1 is used, the result will be decreased by 1
// using 0 value will by default set 1 as the intial value although 0 will be printed as the first value
x=0;
do
{
//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;
x++;
sax += x * x;
}
while (x<=v);
return 0;
}
Comments
Post a Comment
Thanks for your comments.