Question #256939

Ask the user to enter 10 positive integers and find the maximum and minimum number, if the user enters a negative number exit the program displaying the message “NOT COOL”. If all numbers are positive display the maximum and minimum numbers as well as if they are even or odd. We can exit the program using exit(1); statement. Sample Input 20 12 891 981 750 400 3 5 20 2 Sample Output The maximum number is 981 and it is an Odd Number. The minimum number is 2 and it is an Even Number.

Expert's answer

#include<conio.h>
#include<stdio.h>
#include<stdlib.h>




int main(){
	
	int number;
	int minNumber=10000000;
	int maxNumber=-10000000;
	//Ask the user to enter 10 positive integers and find the maximum and minimum number, 
	
	
	
	printf("Enter 10 numbers:\n");
	for(int i=0;i<10;i++){
		scanf("%d",&number);
		//if the user enters a negative number exit the program displaying the message “NOT COOL”. 
		if(number<0){
			printf("\nNOT COOL\n");
			//We can exit the program using exit(1); statement.
			exit(1);
		}
		if(number<minNumber){
			minNumber=number;
		}
		if(number>maxNumber){
			maxNumber=number;
		}
	}
	//If all numbers are positive display the maximum and minimum numbers as well as if they are even or odd. 
	if(maxNumber%2==0){
		printf("The maximum number is %d and it is an Even Number\n",maxNumber);	
	}else{
		printf("The maximum number is %d and it is an Odd Number\n",maxNumber);	
	}
	if(minNumber%2==0){
		printf("The minimum number is %d and it is an Even Number\n",minNumber);	
	}else{
		printf("The minimum number is %d and it is an Odd Number\n",minNumber);	
	}
	


	getchar();
	getchar();


	return 0;
}

LATEST TUTORIALS
APPROVED BY CLIENTS