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

  1. #16
    Registered User
    Join Date
    May 2011
    Around 8.3 light-minutes from the Sun
    Ok, in C anything nonzero evaluates to true, conversely 0 evaluates to false. So you could:
    int main (void){
    	int num;
    	printf("Enter a Number to Test if it is Prime: ");
    		printf("%d is prime", num);
    		printf("%d is not prime", num);
    } /* End of Main*/
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  2. #17
    Join Date
    Aug 2010
    Ontario Canada
    Note that N is unused and you are calling is_prime twice for no good reason...
      Y = is_prime (num);
       N = is_prime (num);
       if (Y == 1)
        printf("%d is a Prime Number\n", num);
         printf("%d is NOT a Prime Number\n", num);
    You could have also done this...
    if (is_prime ( num ))
      printf("%d is a prime number.\n\n", num);
      printf("%d is not a prime number.\n\n",num);
    or maybe this...
    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...
    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...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data type mismatch in criteria expression ERROR
    By Aga^^ in forum C# Programming
    Replies: 2
    Last Post: 02-11-2009, 01:21 AM
  2. Yahoo Answers Type Website
    By Peckle in forum A Brief History of
    Replies: 3
    Last Post: 07-21-2008, 10:30 AM
  3. Incompatible Pointer Type warnings
    By trillianjedi in forum C Programming
    Replies: 3
    Last Post: 06-11-2008, 04:16 PM
  4. Type mismatch warning
    By Opel_Corsa in forum C Programming
    Replies: 5
    Last Post: 10-11-2006, 10:34 AM