Hi ,
Here is the small program,generating a circle in c with ASCII in linux environment.
Surface:50X50
Radius:15
Formula: (x-CC)2+(y-CC)2=radius2
Here CC=Circle Center
x,y are the surface pointers.
#include "stdio.h"
#include "math.h"
int main()
{
int i,j,rad;
rad=15;
for (i=0; i<50; i++)
{
for (j=0; j<50; j++)
{
if(sqrt((j-(50)/2)*(j-(50)/2) + (i-(50)/2)*(i-(50)/2))<=rad)
printf(".");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Complile:-
--------------
gcc -o circ circ.c -lm
Here is the small program,generating a circle in c with ASCII in linux environment.
Surface:50X50
Radius:15
Formula: (x-CC)2+(y-CC)2=radius2
Here CC=Circle Center
x,y are the surface pointers.
#include "stdio.h"
#include "math.h"
int main()
{
int i,j,rad;
rad=15;
for (i=0; i<50; i++)
{
for (j=0; j<50; j++)
{
if(sqrt((j-(50)/2)*(j-(50)/2) + (i-(50)/2)*(i-(50)/2))<=rad)
printf(".");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Complile:-
--------------
gcc -o circ circ.c -lm
Comments
Post a Comment