Asks for a number from 1 to 100 and tells then whether or not their choice is equally divisible by 2 through 9 - C Operator

C examples for Operator:Arithmetic Operator

Description

Asks for a number from 1 to 100 and tells then whether or not their choice is equally divisible by 2 through 9

Demo Code

#include <stdio.h>

int main()//ww  w.  j a  va2s.  c om
{
    int i;

    printf("Pick an integer between 1 and 100 ");
    printf("(The higher the better!)\n");
    scanf(" %d", &i); //remember for an int, you do need the &
    printf("%d %s divisible by 2.", i, (i % 2 == 0) ? ("is") : ("is not"));
    printf("\n%d %s divisible by 3.", i, (i % 3 == 0) ? ("is") : ("is not"));
    printf("\n%d %s divisible by 4.", i, (i % 4 == 0) ? ("is") : ("is not"));
    printf("\n%d %s divisible by 5.", i, (i % 5 == 0) ? ("is") : ("is not"));
    printf("\n%d %s divisible by 6.", i, (i % 6 == 0) ? ("is") : ("is not"));
    printf("\n%d %s divisible by 7.", i, (i % 7 == 0) ? ("is") : ("is not"));
    printf("\n%d %s divisible by 8.", i, (i % 8 == 0) ? ("is") : ("is not"));
    printf("\n%d %s divisible by 9.", i, (i % 9 == 0) ? ("is") : ("is not"));

    return 0;
}

Result


Related Tutorials