Computer Science, asked by sobanaayyalusamy1, 8 months ago

write c program for accept a number X as input if X is a prime number then print prime if X is not prime print odd if X is an odd if X is not prime print even if X is an even

Answers

Answered by xMaNaSx
13

Answer:

Sorry but  this in python. But you may able to convert this into C

Explanation

x = int(input("Enter a number: "))

if x == 2 or x == 3 or x == 5 or x == 7:

   print(x, "is a prime number")

elif x % 2 == 0 or x % 3 == 0 or x % 5 == 0 or x % 7 == 0:

   if x % 2 == 1:

       print(x, "is an odd number")

   else:

       print(x, "is an even number")

else:

   print(x, "is a prime number")

Answered by aadimajestic26
5

Answer:

Hi guys this is the code done with c language, don’t get too puzzled with conditions ,you just have to focus on main “prime numbers” condition.

Explanation:

#include<stdio.h>

void main()

{    

int x;

   scanf("%d",&x);

   int i,flag=0;

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

{

       if(x%i==0)

//by aaditya

{

           flag=1;

break;

       }

}

   if(flag==0)

{

       printf("prime");

}

   else

{

   if(flag==1 && x%2!=0)

{

           printf("odd");

}

       else

{

           printf("even");

}

   }

}

Similar questions