Advertisement
kkricardokaka95

Consumer Producer

Aug 3rd, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int produced=0;
  4.  
  5. void prod(int a[5])
  6. {
  7.     int i;
  8.     int produced;
  9.     for(i=0;i<5;i++)
  10.     {
  11.         a[i]=(int)rand();
  12.         printf("Produced %d\n",++produced);
  13.     }
  14. }
  15.  
  16. void cons(int a[5])
  17. {
  18.     int i;
  19.     int count = 4;
  20.     int consumed = 0;
  21.     a:prod(a);
  22.     for(i=4;i>=0;i--)
  23.     {
  24.         printf("Consumed %d\n",++consumed);
  25.     }
  26.     count--;
  27.     if(count)
  28.         goto a;
  29. }
  30.  
  31. void main()
  32. {
  33.         int a[5];
  34.         cons(a);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement