Click here to Skip to main content
15,891,762 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I´m trying to make a spiral pattern (just starting with C programming) and I don´t know hot to make inside of the spiral. I´ve tried to do it manually to n=15(like spiral 15x15) but it got messy when n=12 and more.

What I have tried:

For now I have the "cover" of the spiral:

<pre>int main()
{
		int N;
		scanf("%d", &N);
		for(int i = 0 ; i < N ; i++){
			for(int j = 0 ; j < N ; j++){
				if(i == 0 || i == N-1 || j == 0 || j == N-1) {
					if (i == 1 && j == 0) {
						printf(".");
					}else {
						printf("#");
					}
				}else {
					printf(".");
				}
			}
			printf("\n");
		}
	}


For example:

For n=5 it looks like this

#####
....#
#...#
#...#
#####


For n=10 like this:

##########
.........#
#........#
#........#
#........#
#........#
#........#
#........#
#........#
##########



What I want is a spiral like this:

For example for n=7 it is:

#######
......#
#####.#
#...#.#
#.###.#
#.....#
#######
Posted
Updated 24-Dec-17 19:47pm
Comments
Nakhia_ind 26-Dec-17 9:35am    
Please can explain briefly

1 solution

Quote:
I´ve tried to do it manually to n=15(like spiral 15x15) but it got messy when n=12 and more.

Sample of what goes messy is what is interesting.
Quote:
How to make inside of the spiral pattern

Advice:
- Use a 2D array where you draw the spiral then print the array.
- Fill the array as you would draw the spiral with a pencil.

This way, you will print any thing, no matter how complicated is the drawing.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900