Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <limits.h>
- #include "main_lib.h"
- void wypisz_tablice(int** tab)
- {
- int i,j;
- for(i = 0;i < N; i++)
- {
- printf("\n");
- for(j = 0; j < M; j++)
- {
- printf("%3d\t",tab[i][j]);
- }
- }
- }
- /* zad1 */
- int **inicjuj_tablice_wart_losowymi()
- {
- int** tab;
- int i,j;
- // alokacja pamieci
- tab = (int**)malloc(N*sizeof(int*));
- for(i = 0; i < N; i++)
- {
- tab[i] = (int*)malloc(M*sizeof(int));
- }
- // wypelnij losowymi
- for(i = 0; i < N; i++)
- {
- for(j = 0; j < M; j++)
- {
- tab[i][j] = rand()% 201 - 100;
- }
- }
- return tab;
- }
- /* zad2 */
- void zwolnij_tablice(int **tab)
- {
- int i,j;
- for(i = 0; i < N; i++)
- {
- free(tab[i]);
- }
- free(tab);
- }
- /* zad3 */
- struct element *inicjuj_lancuch(int elements)
- {
- if(elements == 0) return NULL;
- struct element* start = (struct element*)malloc(sizeof(struct element));
- start->value = rand()%201 - 100;
- struct element* prev = start;
- int i;
- for(i = 1; i < elements; i++)
- {
- struct element *newElement = (struct element*)malloc(sizeof(struct element));
- newElement->value = rand()% 201 - 100;
- newElement->next = NULL;
- prev->next = newElement;
- prev = newElement;
- }
- printf("\n");
- return start;
- }
- /* zad4 */
- void zwolnij_lancuch(struct element* lancuch)
- {
- struct element* current = lancuch;
- struct element* temp = NULL;
- while(current != NULL)
- {
- temp = current;
- current = current->next;
- free(temp);
- }
- }
- void wypisz_lancuch(struct element* lancuch)
- {
- while(lancuch != NULL)
- {
- printf("%d\t",lancuch->value);
- lancuch = lancuch->next;
- }
- }
- /* zad5 */
- int ile_ciagow_arytmetycznych(int **tab)
- {
- int result = 0;
- int a0, a1, r;
- int i;
- for(i = 0; i < 3; i++)
- {
- a0 = tab[i][0];
- a1 = tab[i][1];
- r = a1 - a0;
- for(int j = 0; j < 2; j++)
- {
- if(tab[i][j+1] - tab[i][j] != r)
- {
- break;
- }
- }
- result++;
- }
- return result;
- }
- /* zad6 */
- struct point znajdz_sume_minimalna(int **tab)
- {
- struct point result;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement