BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to check if a number is divisible by 3 and 5

Last Updated: May 17, 2024 by Chaitanya Singh | Filed Under: C Programs

In this article, we will write a very simple C program to check if a number is divisible by 3 and 5.

C Program to check if a given number is divisible by 3 and 5

This program first takes an integer number as an input from the user. Then, it checks if the number is divisible by both 3 and 5 using the modulo operator %. If the remainder when dividing the input number by 3 is 0 and the remainder when dividing by 5 is 0, then the number is divisible by both 3 and 5, else it is not divisible by both.

#include <stdio.h>

int main() {
int num;

// Input number from user
printf("Enter a number: ");
scanf("%d", &num);

// Check if the number is divisible by both 3 and 5
if (num % 3 == 0 && num % 5 == 0) {
printf("%d is divisible by both 3 and 5.\n", num);
} else {
printf("%d is not divisible by both 3 and 5.\n", num);
}

return 0;
}

Output:

Output 1:

Enter a number: 15
15 is divisible by both 3 and 5.

Output 2:

Enter a number: 12
12 is not divisible by both 3 and 5.

Top Related Articles:

  1. C Program to Find ASCII value of a Character
  2. C Program to calculate Area of an Equilateral triangle
  3. C Program to read and print employee details using structure
  4. C Program to find sum of array elements
  5. C Program to Read the First Line From a File

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap