top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Write a C program to print a circle on the screen i.e. stdout?

0 votes
769 views
Write a C program to print a circle on the screen i.e. stdout?
posted Dec 19, 2014 by Chirag Gangdev

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
 
Best answer

Suppose you want to print a circle for the given radius and want to use some character to draw the circle. You can use the following

#include <stdio.h>

void circle(int x, char c)
{
    int i,j;
    for(i=-x;i<x;i++)
    {
        for(j=-x;j<x;j++)
        {
            if((i*i+j*j)<(x*x))
                printf("%c",c);
            else
                printf(" ");
        }
        printf("\n");
    }
}

int main(void) {
        circle(20, '*');
        return 0;
}

Remember vertical alignment and horizontal are not the same so it could not look as circle but this is the algo if applied on pixcel it will look perfect. Based on the mathematical formula x^2+y^2 = r^2

answer Dec 19, 2014 by Salil Agrawal
Thanks Sir...
My Pleasure...
Similar Questions
+1 vote

How to create a c program to print a alphabet in the form of stars for ex.
A should be printed something like

   *
  * *
 *****
*     *

Do we have any standard algo???

+7 votes

Can anybody suggest how can we create a program in C to know the last modification date of any file?

...