Skip to content

Instantly share code, notes, and snippets.

@Hajto
Created October 22, 2016 18:09
Show Gist options
  • Save Hajto/94176f20e4407dfbe0102b27ae93bf73 to your computer and use it in GitHub Desktop.
Save Hajto/94176f20e4407dfbe0102b27ae93bf73 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Wersja L
int main(){
int** matrix;
int width = 0;
int counter = 0;
printf("Wprowdz rozmiar K\n");
scanf("%d", &width);
matrix = malloc(width * sizeof(int*));
for(int i = 0; i < width; i++){
matrix[i] = malloc(sizeof(int) * width);
printf("Prowadz wiersz %d, liczby oddziel spacjami:\n",i+1);
for(int j = 0; j < width; j++){
int temp;
scanf("%d", &temp);
matrix[i][j] = temp;
}
}
for(int i = 0; i < width; i++){
for(int j = 0; j <= i; j++){
int value = matrix[i][j];
if( value == 0){
counter++;
}
printf("%d ",value);
}
printf("\n");
}
printf("\n --------- \n");
for(int i = 0; i < width; i++){
free(matrix[i]);
//printf("\n");
}
free(matrix);
printf("Pod diagoala jest %d zer(a)\n", counter);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment