Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Print out a Circle using a Matrix

$
0
0
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);
            int radiussquared= radius* radius;
            
            if((bsquared+asquared)<(radiussquared))
                matrix[x][y]='*';
            
            else
                
                matrix[x][y]='-';
            
            cout<<matrix[x][y]<<" ";
            
        }
        
        cout<<endl;
        
    }
    
}


int main()
{
    int radius=8;
    int length=20;
    
    
    char matrix[length][radius];
    circle (matrix, length, radius);
    
    
}



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>