C++ Program To Display A Circle ( without using graphics.h)

// To illustrate a circle
#include<iostream>
using namespace std;

int main()
{
float r;
cout<< " Enter the Radius"<<endl;
cin>> r;
float pr = 2; // pr is the aspected pixel ratio which is almost equal to 2

for (int i = -r; i <= r; i++) // loop for horizontal movement
{
for (int j = -r; j <= r; j++) // loop for vertical movement
{
float d = ((i*pr)/r)*((i*pr)/r) + (j/r)*(j/r); //multiplying the i variable with pr to equalize pixel-width with the height
if (d >0.95 && d<1.08) // approximation
{
cout << "*";
}
else
{
cout << " ";
}
}
cout << endl;
}
return 0;
}

Screenshot displaying the output :

Image

There, came a Sigh Of relief, on seeing this output. Our faces finally glowed with those Smiles that this ‘petty’ Circle had blocked :p These were the smiles that had traversed longer paths, may be more than the circumference of this circle :p…The path that started from the vertically elongated circle & ended at the perfect looking circle (via horizontally elongated circle :p )...The path that defines the journey that made A circle look like a circle :p 🙂

4 thoughts on “C++ Program To Display A Circle ( without using graphics.h)

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: