Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- struct Node{
- int x;
- struct Node *next;
- };
- int main(){
- srand(time(NULL));
- struct Node *head;
- head = malloc(sizeof(struct Node));
- head->x = (rand() % 9 + 1 );
- printf ("%d \n", head->x);
- struct Node *tail;
- tail = head;
- for(int i=0; i<99; i++){
- struct Node *tmp;
- tmp = malloc(sizeof(struct Node));
- tmp->x = (rand() % 9 + 1 );
- tail->next=tmp;
- tmp->next=NULL;
- tail = tmp;
- printf("%d \n", tmp->x);
- }
- // szukamy min
- int min = head->x;
- int count = 0;
- struct Node *temp = head;
- for(int i=0; i<100; i++){
- if (min > temp->x){
- min = temp->x;
- count = 1;
- }
- else if( min == temp->x){
- count++;
- }
- temp=temp->next;
- }
- printf("ilosc wystepowania minimalnej liczby: %d \n", count);
- free(temp);
- free(head);
- free(tail);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement