A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to check if a number is divisible by 3
Q:

C program to check if a number is divisible by 3

belongs to collection: C programs - Basic C Programs

0

This C programming example is to check whether a given number is divisible by 3 or not. You can achieve this by applying multiple programming logic. Here, modulus operator (%) is used to find out if entered number is divisible by 3. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C program to check if a number is divisible by 3 - Source code

#include <stdio.h>
 
int main()
{
    int number;
    printf("Enter number:\n");
    scanf("%d",&number);
 
    if ((number % 3) == 0)
 
        printf("%d is a multiple of 3",number);
    else
        printf("%d is not a multiple of 3",number);
 
    return 0;
}

Program Output

Case 1:

Enter number:
493648
493648 is not a multiple of 3

Case 2:

Enter number:
98274651
98274651 is a multiple of 3

Program Explanation

1. This program simply asks user to input an integer number.

2. In order to check for its divisibility by 3, modulus operator (%) is used. This operator return the remainder after dividing the given number by another number.

3. If the modulus operator return 0 as remainder, the number is multiple of 3. Otherwise, it is not a multiple of 3.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to convert an binary number to octal... >>
<< C program to calculate the sum of odd and even num...