# Print out a Circle using a Matrix

Page 1 of 1

## 3 Replies - 1648 Views - Last Post: 19 February 2013 - 04:35 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=312705&amp;s=a2aaa0e88eac43d2e00e1bf5c10e59ca&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 narabo

Reputation: 0
• Posts: 7
• Joined: 19-February 13

# Print out a Circle using a Matrix

Posted 19 February 2013 - 04:15 AM

We have to print out a circle using matrices and I'm having trouble sending the matrix to the circle function. There may be other problems though also...

Thanks!

```//This program will accept a radius of a circle and print out said circle using a matrix

#include <iostream>
using namespace std;

//this function fill in a matrix a circle

void circle (char matrix[ ][20], int length, int radius)

{
int middle=(length/2);

for(int y=0 ; y<length ; y++)

{
int asquared=(middle-y)*(middle-y);

for(int x=0 ; x<length ; x++)

{
int bsquared= (middle-x)*(middle-x);

matrix[x][y]='*';

else

matrix[x][y]='-';

cout<<matrix[x][y]<<" ";

}

cout<<endl;

}

}

int main()
{
int length=20;

}

```

Is This A Good Question/Topic? 0

## Replies To: Print out a Circle using a Matrix

### #2 raghav.naganathan

• Perfectly Squared ;)

Reputation: 410
• Posts: 1,449
• Joined: 14-September 12

## Re: Print out a Circle using a Matrix

Posted 19 February 2013 - 04:25 AM

Well, you are not sending any value of your matrix to your Circle function.

You need to provide some scanf statements in a for loop for collecting the values that you want to provide in the matrix.

regards,
Raghav

### #3 narabo

Reputation: 0
• Posts: 7
• Joined: 19-February 13

## Re: Print out a Circle using a Matrix

Posted 19 February 2013 - 04:28 AM

sorry, im pretty new at this and didnt really understand what you said...

### #4 jimblumberg

Reputation: 5447
• Posts: 16,972
• Joined: 25-December 09

## Re: Print out a Circle using a Matrix

Posted 19 February 2013 - 04:35 AM

There are several things wrong. In C++ the size of an array must be a compile time constant so the following is illegal.

```void circle (char matrix[ ][20], int length, int radius);

int main()
{
int length=20;

```

If you change the radius and length to const int variables then that part should be okay. However you seem to have your matrix sizes different in main than what you have in your function signature. This is where defining these two constant variables as global is considered acceptable
```const int radius=8;
const int length=20;

int main()
{