Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- FILE *izlez = fopen("shema.txt", "w");
- int broj;
- scanf("%d", &broj);
- int n; // kolku ke bide golema matricata
- for(int i = 1; i <= 20; i++) {
- if(i * i >= broj) {
- n = i;
- break;
- }
- }
- int matrica[n][n];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- matrica[i][j] = 0;
- }
- }
- int brojac = 1;
- for(int j = 0; j < n; j++) {
- if(j % 2 == 0) { // ako imame parna kolona odime od gore nadole
- for(int i = 0; i < n; i++) {
- if(brojac <= broj) {
- matrica[i][j] = brojac;
- brojac++;
- }
- }
- }
- else {
- for(int i = n - 1; i >= 0; i--) {
- if(brojac <= broj) {
- matrica[i][j] = brojac;
- brojac++;
- }
- }
- }
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < n; j++) {
- fprintf(izlez, "%d ", matrica[i][j]);
- }
- fprintf(izlez, "\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement