#Need help with making a number spread pattern
13 messages · Page 1 of 1 (latest)
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.
#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.
Omg
Hi.
think of it line by line
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
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.