training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

even.c (540B)


      1 /* Esercizio 5.18 */
      2 
      3 #include <stdio.h>
      4 
      5 int even(int);
      6 
      7 int main()
      8 {
      9    int num;
     10 
     11    printf("Give me a number (%d to end): ", EOF);
     12    scanf("%d", &num);
     13    while(num != EOF) {
     14       printf("%d ", num);
     15       if(!even(num))
     16 	 printf("is even\n");
     17       else
     18 	 printf("is odd\n");
     19 
     20       printf("Give me a number (%d to end): ", EOF);
     21       scanf("%d", &num);
     22    } /* end while (num) */
     23 
     24    return 0;
     25 } /* E0F main */
     26 
     27 /* check if n is even */
     28 int even(int n)
     29 {
     30    if( !(n % 2))
     31       return 0;
     32    else
     33       return 1;
     34 } /* eof even() */
     35