In: Computer Science
Write down a while loop that calculates and displays the SQUARE of ten ODD numbers (from 1 to 19) in a loop style execution:
C++
A while loop cpp Program to calculates and displays the SQUARE of ten ODD numbers (from 1 to 19).
Screenshot of Source Code:
Source Code:
#include <iostream>
int main()
{
// initailized integer vairable number to
store and display square of odd numbers
int number;
while(number < 20) // this while loop will
iterate number 20 times
{
if(number % 2 == 1) //
condition to check or filter only odd numbers
{
std::cout
<< " " << number * number; // this line will
display square of all odd number from 1 to 19
}
number++; // this will increase the value of number by +1
each time untill condition of while loop is not to be
fullfilled
}
return 0; // here return will be zero because
program is not returning anything
}
Output:
Note: If you are satisfied with this solution then like and review this post.