88.9k views
1 vote
Using while loop, write a C++ program that will compute and display the square roots of the first 25 odd positive integers starting from 1.

1 Answer

3 votes

#include <iostream>

#include <cmath>

int main() {

int i = 1; // initialize counter to 1

while (i <= 25) { // loop until counter reaches 25

std::cout << "The square root of " << i << " is " << sqrt(i) << std::endl;

i += 2; // increment counter by 2 to get the next odd number

}

return 0;

}

User Andreas Lochbihler
by
4.0k points