programming-examples/c++/Others/A Simple for Statement - generate the square root of 1 to 10.cpp

20 lines
428 B
C++
Raw Normal View History

2019-11-15 12:59:38 +01:00
A Simple for Statement - generate the square root of 1 to 10
#include <iostream>
#include <math.h> // for newer compilers, use <cmath>
using namespace std;
int main()
{
int num;
double sq_root;
for(num=1; num < 10; num++) {
sq_root = sqrt((double) num); //casting num from integer to double
// then taking its square root
cout << num << " " << sq_root << '\n';
}
return 0;
}