C++ Code that uses a 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()
/*
C++ program that uses a 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 1
x=1;
while (x<=v)
{
sax += x*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()
/*
C++ program that uses a 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 1
x=1;
while (x<=v)
{
sax += x*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.