# Warnings: Type Mismatch, functions, parameters? Homework: Guidance, not answers.

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 08-02-2011
AndrewHunter
Ok, in C anything nonzero evaluates to true, conversely 0 evaluates to false. So you could:
Code:

```int main (void){                 int num;                 printf("Enter a Number to Test if it is Prime: ");         scanf("%d",&num);         if(is_prime(num))                 printf("%d is prime", num);         else                 printf("%d is not prime", num);         system("PAUSE");         return(0); } /* End of Main*/```
• 08-02-2011
CommonTater
Note that N is unused and you are calling is_prime twice for no good reason...
Code:

```  Y = is_prime (num);   N = is_prime (num);   if (Y == 1)   {     printf("%d is a Prime Number\n", num);     }     else     {     printf("%d is NOT a Prime Number\n", num);     }```
You could have also done this...
Code:

```if (is_prime ( num ))   printf("%d is a prime number.\n\n", num); else   printf("%d is not a prime number.\n\n",num);```
or maybe this...
Code:

```printf ("%d is ",num); if (!is_prime (num))   printf("not "); printf("a prime number\n\n");```

In your is_prime function you could have done this...
Code:

```int is_prime (int p_num) { int i;   if ( ! (p_num & 1) )  // prime numbers are all odd numbers     return 0;  for(i = 3; i < p_num; i ++)  // no need to check 1 or 2   if (p_num%i==0)     return 0;  return 1; }```

There are always other ways of doing things...
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12