0

# How do I find the sq of all even numbers between 10 to 30 using while and do while loop?

29th Jul 2016, 4:34 AM
SrĂŹnĂ­dhĂŽ Ĺ Ă¨ĹhĂŁdrĂŽ
0
#include <iostream> #include <math.h> using namespace std; int main() { int a = 1; while (a < 2) { for (int a = 10; a < 31; a+=2) { cout << pow(a,2) << endl; } a++; } return 0; } --------------------- #include <iostream> #include <math.h> using namespace std; int main() { int a = 10; do { cout << pow(a,2) << endl; a = a + 2; } while(a < 31); return 0; }
29th Jul 2016, 7:03 AM
Jaque
0
why did you use #include <math.h> ?? wht does it mean jaque!!???
29th Jul 2016, 7:55 AM
Manish Pant
0
math.h allows you to use different mathematical functions, I had to declare (C library) math.h to use pow(base,exp). It's like <stdio.h> with printf. It allows you to use alot more functions like sqrt(data type variable);. Tip: You can also sqrt with pow(base,0.5) make sure you watch data types.
29th Jul 2016, 8:07 AM
Jaque
0
so, without this statmnt can we also print something and what's this pow .... its a basic of c++ or high lvl
29th Jul 2016, 8:11 AM
Manish Pant
0
Yes you can print without it it's just optional for doing additional maths. pow is raising a number to a certain power ex. 5^2 is 5 * 5 , 5^3 5*5*5. It's a basic but idk if they cover it in this course. <iostream> is what you'll mainly be using here but there are others like <ctime> , etc you'll see in the course.
29th Jul 2016, 8:16 AM
Jaque
0
#include <iostream> using namespace std; int main() { int a = 10; do { cout << a * a << endl; a = a + 2; } while(a < 31); return 0; } is it not using math.h or pow
29th Jul 2016, 8:25 AM
Jaque
0
thanks so much guys.
29th Jul 2016, 11:11 AM
SrĂŹnĂ­dhĂŽ Ĺ Ă¨ĹhĂŁdrĂŽ