How to create a code on a number divisible by 5 or 3 but not divisible by 15

Why is my code not working

Repl link:
https://replit.com/@chinthalamahesh/C?mobileWebview=1&mobileBridge=1&hideBottomBar=1&forceTheme=replitDark&fun=1#main.c

code snippet

Hey @chinthalamahesh welcome to the forums!

Is this a school project? Here is some help: Your divisible by 5 and 3 were in a nested loop so the rest of it didnā€™t run. Here is your updated code:

#include <stdio.h>
int main() {
    int x;
    printf("Enter a number: ");
    scanf("%d", &x);

    if (x % 15 == 0) {
        printf("The number is not valid");
    } else if (x % 5 == 0 || x % 3 == 0) {
        printf("The number is valid");
    } else {
        printf("The number is not valid.");
    }

    return 0;
}

@chinthalamahesh Is this a school project?

1 Like