Creative Commons License Foxbond's Repo

/** (c) 2015 Michał (Foxbond) Chraniuk */
#include <stdio.h>

int **createArray (int size){
		int** arr = (int**)malloc(size*size*sizeof(int));
		int i;
		for (i=0;i<size;i++){
		   arr[i] = (int*)malloc(size*size*sizeof(int));
		}
		return arr;
}

void fillArray (int** array, int size){
		 int i,ii,c;
		 c=0;
		 for (i=0;i<size;i++){
		 		for (ii=0;ii<(i+1);ii++){
					 array[i][ii] = ++c;
			  } 
		 }
}

void displayArray (int** array, int size){
		 int i,ii;
		 for (i=0;i<size;i++){
		 		for (ii=0;ii<(i+1);ii++){
					 printf("%4d", array[i][ii]);
			  }
			  printf("\n");
		 }
}



int main () {
		
		int w;
		printf("Podaj ilosc wierszy: ");
		scanf("%d", &w);
		
		int** tab = createArray(w);
		fillArray(tab, w);
		displayArray(tab, w);
		
		getch();
		return 0;
}

> Back