Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

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

πŸŒ™