Write a program to check entered number is divisible by 5 or not
please kindly say the answer
Answers
Answer:
This is the required program for the question.
1. In Java.
import java.util.*;
public class Java {
public static void main(String[] args) {
int n;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
n=sc.nextInt();
if(n%5==0)
System.out.println("Number is divisible by 5.");
else
System.out.println("Number is not divisible by 5.");
sc.close();
}
}
2. In Python.
n=int(input("Enter a number: "))
if n%5==0:
print("Number is divisible by 5.")
else:
print("Number is not divisible by 5.")
3. In C.
#include <stdio.h>
void main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
if(n%5==0)
printf("Number is divisible by 5.");
else
printf("Number is not divisible by 5.");
}
4. In C++
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter a number: ";
cin >> n;
if(n%5==0)
cout << "Number is divisible by 5.";
else
cout<< "Number is not divisible by 5.";
return 0;
}
Explanation:
- A number is said to be divisible by 5 if the remainder obtained when the number is divided by 5 is 0.
- To obtain the remainder, the modulus operator is used (symbol - %). So, if the number (n) is divided by 5, remainder is equal to n%5.
- Now, we will check if n%5 is equal to zero or not. If true, number is divisible by 5 else not.
See the attachment for output ☑.