Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include"stdafx.h"
- #include"iostream"
- using namespace std;
- /*write only fucntion to print the sum and average of number in a circular queue with size(10)*/
- #define size 10
- struct cqueue {
- int rear, front;
- int data[size];
- };
- void enqueue(cqueue *s,int item)
- {
- if ((s->rear == size - 1 && s->front == 0) || (s->rear < s->front))
- cout << "cqueue is full\n";
- else
- {
- s->rear++;
- s->data[s->rear] = item;
- if (s->front == -1)
- s->front = 0;
- }
- }//end of enqueue
- void av_func(cqueue *c)
- {
- int i,sum=0,av;
- i = c->rear;
- for (size_t i = 0; i < size; i++)
- {
- sum += c->data[i];
- cout << c->data[i]<<endl;
- }
- av = sum / size;
- cout << "the av : " << av << endl;
- }
- int main()
- {
- cqueue c;
- c.front = -1;
- c.rear = -1;
- int item, i,sum=0;
- float av;
- for (size_t i = 0; i < size; i++)
- {
- cout << "Input element " << i << " element : ";
- cin >> item;
- enqueue(&c, item);
- }
- av_func(&c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment