Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 400
- int main()
- {
- int n;
- scanf("%d",&n);
- int temp;
- for(int i=0;i<=n;i++){
- if(i*i>=n){
- temp=i;
- break;
- }
- }
- int brojac = 1;
- int mat[temp + 1][temp + 1];
- for(int i = 0; i < temp; i++) {
- for(int j =0; j < temp;j ++) {
- mat[i][j] = 0; // popolni celata matrica na pocetokot da e 0
- }
- }
- for(int j=0;j<temp;j++){
- if(j % 2 == 0) { // odime od gore nadolu
- for(int i=0;i<temp;i++){
- if(brojac <= n) {
- mat[i][j] = brojac;
- brojac += 1;
- }
- }
- }
- else { // odime od nadole gore
- for(int i=temp - 1; i >= 0; i--) {
- if(brojac<=n){
- mat[i][j]=brojac;
- brojac+=1;
- }
- }
- }
- }
- for(int i=0;i<temp;i++){
- for(int j=0;j<temp;j++){
- printf("%d ",mat[i][j]);
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment