Basic programming C Question -


ok, i'm trying write program can check see if number evenly divisible 2, 3, 4 or 5.

for example if user enters 8, output be:

“8 divisible 2” “8 divisible 4”

my program:

#include<stdio.h> #include<conio.h>   main(){      int num, even, oddthree, evenfour, oddfive;        printf("please enter number: ");     scanf("%d",&num);      = (num % 2 == 0);      oddthree = (num % 3 == 0);      evenfour = (num % 4 == 0);      oddfive = (num % 5 == 0);       if (even){       printf("%d divisible 2\n",num);      }      if(oddthree) {      printf("%d divisible 3\n",num);      }       if (evenfour){       printf("%d divisible 4\n", num);      }      if (oddfive){       printf("%d divisible 5\n", num);      }      else {       printf("%d not divisible 2,3,4 or 5\n", num);      }  getch();   } 

for reason when enter numbers, instance, 12. output is:

"12 divisible 2" "12 divisible 4" "12 not divisible 2,3,4 or 5"

the first 2 statements true, third false.

what i'm doing wrong ?

printf("%d not divisible 2,3,4 or 5\n", num); 

will run times

(oddfive) 

is false. maybe

if (!(even || oddthree || evenfour || oddfive)) {     printf("%d not divisible 2,3,4 or 5\n", num); } 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -