WAP to input an number and check whether it is divisible by 3 and 5 or not
Program
to find out whether a entered number is divisible by 3 and 5 or not
To understand this example, you should have the knowledge of following C programming topics:
- C Programming Operators
- C if, if...else and Nested if...else Statement
This program takes a number from the user and checks whether that number is either divisible by 3 and 5 or not.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include "conio.h"
#include "stdio.h"
void main()
{
int num;
printf("\nEnter
a number ");
scanf("%d",&num);
if(num%3==0)
{
if(num%5==0)
{
printf("\nThe
number %d is divisible by 3 and 5");
}
else
{
printf("\nThe
number %d is divisible by 3 but not by 5");
}
}
else
{
printf("\nThe
number %d is niether divisible by 3 nor by 5");
}
getch();
}
|
Output:
Enter a number 21
Number is divisible by 3 but not by 5
|
Comments
Post a Comment