Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int dd_test(const int *ptr, int width, int height){
- int diag, rest;
- int i, k = 0;
- int temp = 0;
- int counter = 0;
- int watcher = width - 1;
- int size = width * height;
- if(width <= 0 || height <= 0 || width != height || ptr == NULL) return -1;
- for(i = 0; i < size; i++){
- if(i == 0){
- if(*(ptr+i) < 0) {temp = *(ptr+i); temp *= (-1); diag += temp; k++;}
- else {diag += *(ptr+i); k++;}
- }
- else if(i == (width+1) * k){
- if(*(ptr+i) < 0) {temp = *(ptr+i); temp *= (-1); diag += temp; k++;}
- else {diag += *(ptr+i); k++;}
- }
- else if(*(ptr+i) < 0) {temp = *(ptr+i); temp *= (-1); rest += temp;}
- else rest += *(ptr+i);
- if(i == watcher) {
- if(diag > rest) counter++;
- else return 0;
- watcher += width;
- diag = 0;
- rest = 0;
- }
- }
- if(counter == height) return 1;
- return 0;
- }
- int main(){
- int macierz2D[100][100] = {0};
- int height = 5;
- int width = 5;
- int size = height * width;
- int funkcja;
- int k;
- int temp = 0;
- int check;
- int *tablica = 0;
- tablica = *macierz2D;
- printf("Podaj liczby: \n");
- for(k = 0; k < size; k++){
- check = scanf("%d", &temp);
- if(check != 1) { printf("Incorrect input"); return 1; }
- else *(tablica+k) = temp;
- }
- funkcja = dd_test(tablica, width, height);
- if (funkcja == 1) printf("YES");
- else if(funkcja == 0) printf("NO");
- else if(funkcja == -1) printf("Incorrect input");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement