Advertisement
Koelion

Untitled

Jan 25th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. struct Node {
  6.     int x;
  7.     struct Node *next;
  8. };
  9.  
  10. int main() {
  11.     srand(time(NULL));
  12.     struct Node *head;
  13.     head = (Node*)malloc(sizeof(struct Node));
  14.     head->x = (rand() % 9 + 1);
  15.  
  16.     printf("%d \n", head->x);
  17.  
  18.     struct Node *tail;
  19.     tail = head;
  20.  
  21.  
  22.  
  23.     for (int i = 0;i<99;i++) {
  24.         struct Node *tmp;
  25.         tmp = (Node*)malloc(sizeof(struct Node));
  26.  
  27.         tmp->x = (rand() % 9 + 1);
  28.  
  29.         tail->next = tmp;
  30.         tmp->next = NULL;
  31.         tail = tmp;
  32.  
  33.         printf("%d\n", tmp->x);
  34.     }
  35.  
  36.  
  37.     //szukanie min
  38.  
  39.     int min = head->x;
  40.     int count = 0;
  41.     struct Node *temp = head;
  42.     while(temp!=NULL){
  43.         if (min>temp->x) {
  44.             min = temp->x;
  45.             count = 1;
  46.         }
  47.         else if (min == temp->x) {
  48.             count++;
  49.         }
  50.         temp = temp->next;
  51.     }
  52.     printf("ilosc liczb: %d \n", count);
  53.  
  54.     while (head != NULL)
  55.     {
  56.         temp = head->next;
  57.         free(head);
  58.         head = temp;
  59.     }
  60.  
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement