Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int MAXN = 100;
- int p[MAXN][MAXN];
- int main(){
- int N;
- scanf("%d", &N);
- //Para cada camada k da pirâmide, vamos percorrer as linhas i e colunas j da matriz p, com i e j intervalo de k até N-k. Por exemplo, em uma pirâmide de tamanho 5, quando k valer 2 (terceira camada, pois k começa em 0) i e j percorrem as posições 22, 23, 32 e 33.
- for(int k = 0; k < N; k++)
- for(int i = k; i < N - k; i++)
- for(int j = k; j < N - k; j++)
- p[i][j]++;
- for(int i = 0; i < N; i++){
- for(int j = 0; j < N; j++)
- printf("%d ", p[i][j]);
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement