WRITE A PROGRAM TO ACEPT A NUMBER AND CHECK WHETHER THE NUMBER IS DIVISIBLE BY 3 AS WELL AS 5 OTHERWISE DECIDE
IS THE NUMBER DIVISIBLE BY 3 AND NOT BY 5
Answers
Steps -
Step 1 - Start.
Step 2 - Accept a number.
Step 3- Check whether it is divisible by 3 and 5 both. If yes print "the number is divisible by 3 and 5 both" and end the program. If not jump to step 4.
Step 4 - Check whether it is divisible by 3. If yes print "the number is divisible by 3" and end the program. If not jump to step 5.
Step 5 - Check whether it is divisible by 5. If yes print "the number is divisible by 5" and end the program. If not jump to step 6.
Step 6 - Print "the number is not divisible by 3 and 5 both" and end the program.
Step 7 - End.
Program (Using Java):-
import java.util.Scanner;
class d
{
public static void main(String args[])
{
System.out.println("Enter a number");
int n;
Scanner sc=new Scanner(System.in);
n = sc.nextInt();
if(n%3 == 0 && n%5 == 0)
{
System.out.println("The number is divisible by 3 and 5 both");
}
else if(n%3 == 0 && n%5 != 0)
{
System.out.println("The number is divisible by 3 only");
}
else if(n%5 == 0 && n%3 != 0)
{
System.out.println("The number is divisible by 5 only");
}
else
{
System.out.println("The number is not divisible by 3 and 5");
}
}
}
Output:- is in the attachment.
Glossary :-
Answer:
dyowueirbbgeheb
Explanation:
qghwhwhehejevge