c - Determined the PRIME numbers -
is 1
& 0
prime numbers ? because when input 1
& 0
says prime
#include <stdio.h> int main(){ int num, i,y = 0; printf("enter number: "); scanf("%d",&num); for(i = 2; <= num /2; ++i){ if(num % == 0){ y=1; } } printf("the number %d ",num); if (y == 0){ printf("(prime)"); } if(num % 2 == 0){ printf("(even)"); }else printf("(odd)"); printf(" number."); }
can me code
no, neither 0 nor 1 considered prime numbers, is, lowest prime number 2. need change code into, instance:
if (y == 0 && n >= 2)
this covers both 0 , 1 along negative integers (thanks @mikecat)
Comments
Post a Comment