3.5 Divisibility
ā§Š.ā§Ģ āĻŦāĻŋāĻāĻžāĻā§āϝāϤāĻž (ā§Ŧ)
[23] āĻāĻāĻāĻŋ āĻĒā§āϰā§āĻŖ āϏāĻāĻā§āϝāĻž āĻā§ā§ āύāĻž āĻŦāĻŋāĻā§ā§ āύāĻŋāϰā§āĻŖā§ āĻāϰāĨ¤
[23.1] āĻŽāĻĄā§āϞāĻžāϏ āĻ āĻĒāĻžāϰā§āĻāϰ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰā§
[23.2] āĻŦāĻŋāĻāĻā§āĻžāĻāĻ āĻ āĻĒāĻžāϰā§āĻāϰ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰ⧠(Similar)
[24] āĻāĻāĻāĻŋ āĻĒā§āϰā§āĻŖ āϏāĻāĻā§āϝāĻž ā§Š āĻĻā§āĻŦāĻžāϰāĻž āĻŦāĻŋāĻāĻžāĻā§āϝ āĻāĻŋāύāĻž āύāĻŋāϰā§āĻŖā§ āĻāϰāĨ¤
[25] āĻāĻāĻāĻŋ āĻĒā§āϰā§āĻŖ āϏāĻāĻā§āϝāĻž ā§Š āĻĻā§āĻŦāĻžāϰāĻž āĻŦāĻŋāĻāĻžāĻā§āϝ āĻšāϞ⧠Fizz, ā§Ģ āĻĻā§āĻŦāĻžāϰāĻž āĻŦāĻŋāĻāĻžāĻā§āϝ āĻšāϞ⧠Buzz, ā§Š āĻ ā§Ģ āĻāĻā§ āĻĻā§āĻŦāĻžāϰāĻž āĻŦāĻŋāĻāĻžāĻā§āϝ āĻšāϞ⧠FizzBuzz āĻĒā§āϰāĻŋāύā§āĻ āĻāϰāĨ¤
[26] āĻāĻāĻāĻŋ āĻāĻāϰā§āĻā§ āĻŦāϰā§āώ āĻ āϧāĻŋāĻŦāϰā§āώ āĻāĻŋāύāĻž āύāĻŋāϰā§āĻŖā§ āĻāϰāĨ¤
[27] āĻāĻāĻāĻŋ āĻāĻāϰā§āĻā§ āĻŦāϰā§āώ āĻļāϤāĻŦāϰā§āώ⧠āĻ āϧāĻŋāĻŦāϰā§āώ āĻāĻŋāύāĻž āύāĻŋāϰā§āĻŖā§ āĻāϰāĨ¤
[28] āĻāĻāĻāĻŋ āĻĒā§āϰā§āĻŖ āϏāĻāĻā§āϝāĻž āĻ āύā§āϝ āĻāĻāĻāĻŋ āĻĒā§āϰā§āĻŖ āϏāĻāĻā§āϝāĻž āĻĻā§āĻŦāĻžāϰāĻž āύāĻŋāĻāĻļā§āώ⧠āĻŦāĻŋāĻāĻžāĻā§āϝ āĻāĻŋāύāĻž āύāĻŋāϰā§āĻŖā§ āĻāϰāĨ¤
āϏāĻŽāĻžāϧāĻžāύ
[23] āĻāĻāĻāĻŋ āĻĒā§āϰā§āĻŖ āϏāĻāĻā§āϝāĻž āĻā§ā§ āύāĻž āĻŦāĻŋāĻā§ā§ āύāĻŋāϰā§āĻŖā§ āĻāϰāĨ¤ (āĻŽāĻĄā§āϞāĻžāϏ āĻ
āĻĒāĻžāϰā§āĻāϰ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰā§, āĻŦāĻŋāĻāĻā§āĻžāĻāĻ āĻ
āĻĒāĻžāϰā§āĻāϰ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻāϰ⧠(Similar))
#include<stdio.h>
int main(){
int n;
scanf("%d", &n);
if(n% 2 == 0){
printf("Even\n");
}
else{
printf("Odd\n");
}
return 0;
}
4
Even
7
Odd
0
Even
[24] āĻāĻāĻāĻŋ āĻĒā§āϰā§āĻŖ āϏāĻāĻā§āϝāĻž ā§Š āĻĻā§āĻŦāĻžāϰāĻž āĻŦāĻŋāĻāĻžāĻā§āϝ āĻāĻŋāύāĻž āύāĻŋāϰā§āĻŖā§ āĻāϰāĨ¤
#include<stdio.h>
int main(){
int n;
scanf("%d", &n);
// Determine if the number is divisible by 3
if(n % 3 == 0){
// Print "Divisible by 3" if the number is divisible by 3
printf("Divisible by 3\n");
}
else{
// Print "Not divisible by 3" if the number is not divisible by 3
printf("Not divisible by 3\n");
}
return 0;
}
9
Divisible by 3
10
Not divisible by 3
27
Divisible by 3
14
Not divisible by 3
[25] āĻāĻāĻāĻŋ āĻĒā§āϰā§āĻŖ āϏāĻāĻā§āϝāĻž ā§Š āĻĻā§āĻŦāĻžāϰāĻž āĻŦāĻŋāĻāĻžāĻā§āϝ āĻšāϞ⧠Fizz, ā§Ģ āĻĻā§āĻŦāĻžāϰāĻž āĻŦāĻŋāĻāĻžāĻā§āϝ āĻšāϞ⧠Buzz, ā§Š āĻ ā§Ģ āĻāĻā§ āĻĻā§āĻŦāĻžāϰāĻž āĻŦāĻŋāĻāĻžāĻā§āϝ āĻšāϞ⧠FizzBuzz āĻĒā§āϰāĻŋāύā§āĻ āĻāϰāĨ¤
#include<stdio.h>
int main(){
int n;
scanf("%d", &n);
// Determine if the number is divisible by 3, 5, or both
if(n % 3 == 0 && n % 5 == 0){
printf("FizzBuzz\n"); // Print "FizzBuzz" if divisible by both 3 and 5
}
else if (n % 3 == 0){
printf("Fizz\n"); // Print "Fizz" if divisible by 3 only
}
else if (n % 5 == 0){
printf("Buzz\n"); // Print "Buzz" if divisible by 5 only
}
return 0;
}
15
FizzBuzz
9
Fizz
10
Buzz
7
(no output)
[26] āĻāĻāĻāĻŋ āĻāĻāϰā§āĻā§ āĻŦāϰā§āώ āĻ
āϧāĻŋāĻŦāϰā§āώ āĻāĻŋāύāĻž āύāĻŋāϰā§āĻŖā§ āĻāϰāĨ¤
#include<stdio.h>
int main(){
int year;
scanf("%d", &year);
if(year % 400 == 0){
// Print "Leap year" if divisible by 400
printf("Leap year\n");
}
else if(year % 100 == 0){
// Print "Not a leap year" if divisible by 100 but not by 400
printf("Not a leap year\n");
}
else if(year % 4 == 0){
// Print "Leap year" if divisible by 4 but not by 100
printf("Leap year\n");
}
else{
// Print "Not a leap year" if not divisible by 4
printf("Not a leap year\n");
}
return 0;
}
2020
Leap year
1900
Not a leap year
2000
Leap year
2024
Leap year
2023
Not a leap year
[27] āĻāĻāĻāĻŋ āĻāĻāϰā§āĻā§ āĻŦāϰā§āώ āĻļāϤāĻŦāϰā§āώ⧠āĻ
āϧāĻŋāĻŦāϰā§āώ āĻāĻŋāύāĻž āύāĻŋāϰā§āĻŖā§ āĻāϰāĨ¤
#include<stdio.h>
int main(){
int year;
scanf("%d", &year);
if (year % 400 == 0) {
// Print "Century Leap year" if divisible by 400
printf("Century Leap year\n");
} else {
// Print "Not a Century Leap Year" if not divisible by 400
printf("Not a Century Leap Year\n");
}
return 0;
}
1900
1900 is not a century leap year
2000
2000 is a century leap year
2100
2100 is not a century leap year
2200
2200 is not a century leap year
2400
2400 is a century leap year
2500
2500 is not a century leap year
[28] āĻāĻāĻāĻŋ āĻĒā§āϰā§āĻŖ āϏāĻāĻā§āϝāĻž āĻ
āύā§āϝ āĻāĻāĻāĻŋ āĻĒā§āϰā§āĻŖ āϏāĻāĻā§āϝāĻž āĻĻā§āĻŦāĻžāϰāĻž āύāĻŋāĻāĻļā§āώ⧠āĻŦāĻŋāĻāĻžāĻā§āϝ āĻāĻŋāύāĻž āύāĻŋāϰā§āĻŖā§ āĻāϰāĨ¤
#include<stdio.h>
int main(){
int numerator, denominator;
printf("Enter the numerator: ");
scanf("%d", &numerator);
printf("Enter the denominator: ");
scanf("%d", &denominator)
// Check if the denominator is zero to avoid division by zero
if(denominator == 0){
// Print an error message for division by zero
printf("Denominator cannot be zero\n");
}
else if(numerator % denominator == 0){
// Print if divisible
printf("%d is exactly divisible by %d\n", numerator, denominator);
}
else{
// Print if not divisible
printf("%d is not exactly divisible by %d\n", numerator, denominator);
}
return 0;
}
20 5
20 is exactly divisible by 5
10 3
10 is not exactly divisible by 3
25 0
Denominator cannot be zero
45 9
45 is exactly divisible by 9
34 7
34 is not exactly divisible by 7
Last updated