Advertisement
luluinstalock

Untitled

Jan 25th, 2016
1,773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     struct Node *head;
  12.     head = malloc(sizeof(struct Node));
  13.     head->x = (rand() % 9 + 1 );
  14.    
  15.     printf("%d \n", head->x);
  16.    
  17.     struct Node *tail;
  18.     tail=head;
  19.    
  20.     struct Node *tmp;
  21.     tmp = malloc(sizeof(struct Node));
  22.    
  23.     for (int i=0;i<99;i++){
  24.        
  25.         tmp->x = (rand() % 9 + 1 );
  26.        
  27.         tail->next=tmp;
  28.         tmp->next=NULL;
  29.         tail=tmp;
  30.        
  31.         printf("%d\n", tmp->x);
  32.     }
  33.    
  34.    
  35.     //szukanie min
  36.    
  37.     int min = head->x;
  38.     int count = 0;
  39.     struct Node *temp = head;
  40.     for(int i=0; i<100; i++){
  41.         if(min>temp->x){
  42.             min=temp->x;
  43.             count=1;
  44.         }
  45.         else if (min == temp->x){
  46.             count++;
  47.         }
  48.         temp=temp->next;
  49.     }
  50.     printf("ilosc liczb: %d \n", count);
  51.    
  52.     free(head);
  53.     free(tail);
  54.     free(temp);
  55.     free(tmp);
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement