#Need help with making a number spread pattern

13 messages · Page 1 of 1 (latest)

crude sierra
#

The program ask the user to input 1 to 9 continuously as N value and print the nested loop number pattern like the picture.
I think it for a long time but still can’t find the way to make it. How can i do it? Thank you

alpine widgetBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

torn cloud
#

Hi.

#

This is a piece of cake.

#

💪

torn cloud
#

#include <stdio.h>

void display_number_spread_pattern(int n){
int row, col, i, k, m;
for(row = 0; row < n * 2 - 1; row++){
k = row < n ? 1 : -1;
col = (n * 2 - 2) * (row / n) + row * k;
if(row == n - 1){
for(i = 0; i < n * 2 - 1; i++) printf("1");
}
else{
for(i = 0; i <= col; i++) printf("%d", n - col);
m = n - col - 1;
for(i = 0; i < m * 2 - 1; i++){
k = i < m ? 1 : -1;
printf("%d", m - ((m * 2 - 2) * (i / m) + i * k));
}
for(i = 0; i <= col; i++) printf("%d", n - col);
}
puts("");
}
}

int main(){
int n;
scanf("%d", &n);
display_number_spread_pattern(n);
puts("");
return 0;
}

#

Please DM when you see this result.

crude sierra
#

Omg

torn cloud
#

Hi.

pliant hinge
#

the first line starts with 3 and goes down to 1 then back to 3

#

the next line does the same with 2, except this is 2 characters shorter so you pad the remaining spaces with 2

alpine widgetBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.