i am trying to understand nested loops can someone explain to me how it works i don't under stand the concept this is the circle-drawing algorithm
for each row from 0 to diameter, inclusive
for each column from 0 to diameter, inclusive
distance = 4(row-radius)^2 + (column-radius)^2
distance = sqrt(distance)
if (distance > radius) print a space
otherwise print an *
print a newline to end the row
i don't understand for each row from the 0 to diameter part
or the for each column from 0 to diameter
the radius is user input to draw the circle.
also can someone tell me step by step also i need to understand this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include<cstido>
#include <cmath>
int get();
void countdown(int radius);
int main()
{
int calc;
calc=get();
count(calc);
return 0;
}
int get()
{
//get user to enter number and print
//error message if not a number,-,or over 20
//this work fine
}
void countdown(int radius)
{
//this is the problem im having
int distance;
for(int row=0; row<radius; row++){ //should i replace the radius?
for (int column =0; columne<radius; columne++){
distance=4*pow(row-radius,2) + pow(columne-radius,2); //this has distance
distance=sqrt(distance);{ //this also distance maybe mistake?
if (distance>radius){
printf(" ");
}
else{
printf("*");
}
print("\n");
}
}
}
|