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.
#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;
}
Comments
Leave a comment