Answer to Question #249996 in C for Natpu

Question #249996
Write a C PROGRAM to get 10 inputs to store in queue,

count all the even numbers in queue separately and give its output,

count all the odd numbers in queue separately and give its output
1
Expert's answer
2021-10-11T16:08:35-0400
#include <stdio.h> 
//declare our global variables 
#define MAX 10
int numbers[MAX]; 
int head = 0; 
int tail = -1; 
//function to put new element into queue
void enqueue(int data) { 


	if(tail==MAX-1) 
		printf("The queue is full\n\n");
	else { 
		tail++;
		numbers[tail]=data; 
	} 
} 
//function to remove element from the queue
int dequeue() { 
	//declare our local variables 
	int temp; 
	if(tail==-1)
		printf("The queue is empty\n\n"); 
	else { 
		temp=numbers[head];
		for (int i = 0; i < tail - 1; i++){
			numbers[i] = numbers[i + 1];
		}
		tail--;
		return temp; 
	} 
} 
int main() { 
	int evenCounter=0;
	int oddCounter=0;
	int i,number;


	for(i=0;i<10;i++){
		printf("Enter the number %d: ",(i+1));
		scanf("%d",&number);
		enqueue(number);
	}


	for(i=0;i<10;i++){
		number=dequeue();
		if(number%2==0){
			evenCounter++;
		}else{
			oddCounter++;
		}
	}


	printf("The total number of the even values: %d\n",evenCounter);
	printf("The total number of the odd values: %d\n",oddCounter);
	getchar();
	getchar();
	return 0; 
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS