Skip to main content

Featured

Mastering Hollow Square Patterns in C: Stars, Numbers, Alphabets & Binary

πŸ”’ C Program to Print Hollow Continuous Number Square πŸ“„ Source Code: #include <stdio.h> int main() { int num, k = 0; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { if(i == 1 || i == num || j == 1 || j == num) { // k increments sequentially only along the borders printf("%d ", k++); } else { printf(" "); } } printf("\n"); } return 0; } πŸ“‹ Copy Code πŸ’» Expected Output (Input: 5): Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 πŸ”’ C Program to Print Standard Hollow Binary Row Square πŸ“„ Source Code (Fixed Specifier): #include <stdio.h> int main() { ...

Check if a Number is Divisible by 2 and 3 in C

Check if a Number is Divisible by 2 and 3 in C

✅ CHECK IF A NUMBER IS DIVISIBLE BY 2 AND 3 IN C

#include <stdio.h>

int main() {
    int num;

    printf("Enter a number:\n");
    scanf("%d", &num);

    if (num % 2 == 0 && num % 3 == 0) {
        printf("%d is perfectly divisible by both 2 and 3.\n", num);
    } else {
        printf("%d is NOT divisible by both 2 and 3.\n", num);
    }

    return 0;
}
    

🧠 Explanation:

This program checks whether a given number is divisible by both 2 and 3.

  • It uses num % 2 == 0 to check divisibility by 2.
  • And num % 3 == 0 to check divisibility by 3.
  • If both are true, it prints that the number is divisible by both.

πŸ–₯️ Sample Output:

Enter a number:
12
12 is perfectly divisible by both 2 and 3.
    

πŸ”‘ Keywords:

C program to check divisibility, modulus operator, if condition, logical AND, basic C program.

Comments

Popular Posts

πŸŒ™