Question

Write two functions, one that displays a circle and one that displays a rectangle. Use these...

Write two functions, one that displays a circle and one that displays a rectangle. Use these functions to write a complete C program from the following outline:

int main()

{

/* Draw circle */

/* Draw rectangle */

}

Do NOT use #include<graphics.h>

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*
 *  C Program to print cirlce and rectangle
 */

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

void printCircle(int length, int width)
{
  int y, x, radius = 10;

  for (y = width; y >= -width; y -= 2)
  {
    for (x = -length; x <= length; x++)
    {
      if ((int)sqrt(pow(x,2)+pow(y,2)) == 10)
        printf("*");
      else
        printf(" ");
    }
    printf("\n");
  }
}

void printRectangle(int length, int width)
{
  int i, j;

  for (i = 0; i < length; i++)
  {
    for (j = 0; j < width; j++)
    {
      if(i == 0 || i == length-1 || j == 0 || j == width-1)
        printf("* ");
      else
        printf("  ");
    }
    printf("\n");
  }
}

int main()
{ 
  int r=10, length, width;
  
  length = r*1.5, width = r;
  printCircle(length, width);

  printf("\n\n");

  length = 20, width = 10;
  printRectangle(length, width);
  
  return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write two functions, one that displays a circle and one that displays a rectangle. Use these...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT