Program to check a number is divisible by 5 or not

Program to check a number is divisible by 5 or not

Program to check a number is divisible by 5 or not using c programing.

Here you can check whether the given number is divisible by 5 or not. For this we will first apply the condition whether our number is (n % 5 == 0) or not. If it is, then that number is exactly divisible by 5, else that number is not divisible by 5.


Code:

#include <stdio.h>
int main()
{
  int num;
  // Input Number
  printf("Enter an integer:");
  scanf("%d", &num);
  
  //Check divisibility
  if (num % 5 == 0)
  {
    printf("Divisible by 5.");
  }
  else
  {
    printf("Not Divisible by 5.");
  }
  return 0;
}

Explanation:

  1. Input: The program will ask the user for input.
  2. Condition: It checks if the remainder when dividing the number by 5 (number % 5) is 0.
  3. Output: If the remainder is 0,then the number is divisible by 5; otherwise, it is not.

Output:

Enter an integer: 15
Divisible by 5.

Enter an integer: 11
Not Divisible by 5.

*

إرسال تعليق (0)
أحدث أقدم