Computer Science, asked by carolinbenjamin31, 8 months ago

Please fill in the missing lines of code to implement the logic given below. Logic: - Accept a number x as input. - if x is a prime number, print "prime" - if x is not a prime number, then print "odd" if x is an odd number - if x is not a prime number, then print "even" if x is an even number

Answers

Answered by nonigopalbarman857
9

Answer:

if (x is prime) {

} else if (x % 2 == 0){

printf(“even”)

} else {

printf(“odd)

}

The user input has nothing to do with the logic of the code. It would include stdio.h. The implementation of a prime check would depend on whether you want to prioritize memory or CPU and could be done by checking all n up to x/2 as divisors or by creating a bank of primes and looking for x, depending what values you want to accept for x

hope it helps you

Answered by saisujana10052005
0

Answer:

#include<stdio.h>

void main()

{

int x;

scanf("%d",&x);

int flag=-1;

for(int i=2;i<x/2;i++)

{

if(x%i==0)

{

flag=0;

break;

}

}

if(flag==0)

{

if(x%2==0)

printf("even");

else

printf("odd");

}

else

printf("prime");

}

Similar questions