Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define CAPACITY 100
- typedef struct node
- {
- int data;
- struct node *next;
- }node ;
- node*top;
- int size = 0;
- void push(int element)
- {
- if (size >= CAPACITY)
- {
- printf("\tStack Overflow\n");
- return;
- }
- node *N = (node *) malloc(sizeof(node));
- N->data = element;
- N->next = top;
- top = N;
- ++size;
- }
- int pop()
- {
- int data = 0,n;
- node *N;
- N = top;
- data = top->data;
- top = top->next;
- free(N);
- size--;
- return data;
- }
- int main()
- {
- int t,data,i ,sum=0;
- int m,l,x;
- printf("TOTAL INPUT :");
- scanf("%d",&t);
- for(i=1; i<=t; i++)
- {
- scanf("%d",&data);
- push(data);
- }
- printf("TOTAL OUTPUT NUMBER :");
- scanf("%d",&m);
- for(l=0; l<m; l++)
- {
- x=pop();
- printf("%d\n",x);
- sum=sum+x;
- }
- printf("%.2f\n",(float)sum/m);
- }
Advertisement
Add Comment
Please, Sign In to add comment