অধিবর্ষে 366 দিন থাকে যেখানে একটি সাধারণ বছরে 365 দিন থাকে এবং কাজটি হল প্রদত্ত বছরটি অধিবর্ষ কিনা তা প্রোগ্রামের মাধ্যমে পরীক্ষা করা।
বছরকে 400 বা 4 দ্বারা ভাগ করা হয় কিনা তা যাচাই করার মাধ্যমে এর যুক্তি হতে পারে কিন্তু যদি সংখ্যাটিকে কোনো একটি দ্বারা ভাগ করা না হয় তবে এটি একটি সাধারণ বছর হবে।
উদাহরণ
Input-: year=2000 Output-: 2000 is a Leap Year Input-: year=101 Output-: 101 is not a Leap year
অ্যালগরিদম
Start
Step 1 -> declare function bool to check if year if a leap year or not
bool check(int year)
IF year % 400 = 0 || year%4 = 0
return true
End
Else
return false
End
Step 2 -> In main()
Declare variable as int year = 2000
Set check(year)? printf("%d is a Leap Year",year): printf("%d is not a Leap Year",year)
Set year = 10
Set check(year)? printf("%d is a Leap Year",year): printf("\n%d is not a Leap Year",year);
Stop উদাহরণ
#include <stdio.h>
#include <stdbool.h>
//bool to check if year if a leap year or not
bool check(int year){
// If a year is multiple of 400 or multiple of 4 then it is a leap year
if (year % 400 == 0 || year%4 == 0)
return true;
else
return false;
}
int main(){
int year = 2000;
check(year)? printf("%d is a Leap Year",year): printf("%d is not a Leap Year",year);
year = 101;
check(year)? printf("%d is a Leap Year",year): printf("\n%d is not a Leap Year",year);
return 0;
} আউটপুট
2000 is a Leap Year 101 is not a Leap Year