C++ Saved Program: quiescent-life

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include <stdio.h>
#include <math.h>

using namespace std;

#define HEIGHT 30
#define WIDTH 60
#define PI 3.1415
char grid[HEIGHT][WIDTH];

void initcircle(float theta);
void showcircle(void);

int main()
{
    float x, angle;
    /*
    printf("Enter angle: ");
    scanf("%f", &x);
    */
    x = 20;
    if(x>= 360 && x >= 0)
    {
        angle = x*PI/180; // conversion to rads
        initcircle(angle);
        showcircle();
    }
    else
    {
        printf("enter a valid value for angle (between 0~360)");
        return 0;
    }
}  

void initcircle(float theta)
{
    int x,y;
    x = WIDTH*cos(theta);
    y = HEIGHT*sin(theta);
    grid[y][x]= '*';
}

void showcircle(void)
{
    int x,y;
    
    for (y=0; y<HEIGHT; y++)
    {
        for(x=0; x<WIDTH; x++)
        {
            putchar(grid[y][x]);
        }
        printf("\n");
    }
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs