Answer to Question #259269 in C for Shally

Question #259269

Write a program to enter the numbers till the user wants and at the end it should display the




count of even, odd and prime numbers entered.

1
Expert's answer
2021-10-31T12:01:22-0400
#include<stdio.h>
#include<conio.h>
int main()
{
	int number;
	int answer=1;
	int evenCounter=0;
	int oddCounter=0;
	int primeCounter=0;
	int is_Prime;
	int i;
	do
	{
		printf("Enter the integer : ");
		scanf("%d", &number);
		if(number%2==0){
			evenCounter++;
		}else{
			oddCounter++;
		}
		is_Prime = 1;
		for (i = 2; i <= number / 2; i++) {
			if (number % i == 0) {
				is_Prime = 0;
				break;
			}
		}
		if (is_Prime==1) {
			primeCounter++;
		}
		printf("\n\nDo you want to enter another number? '1' for YES and '0' for NO: ");
		scanf("%d", &answer);
	}while(answer==1);
	//count of even, odd and prime numbers entered.
	printf("\n\nYou have entered %d even, %d odd and %d prime numbers.",evenCounter,oddCounter,primeCounter);
	getch();
	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