ปีอธิกสุรทินคือปีที่ประกอบด้วย 366 วัน เราจะพบกับปีอธิกสุรทินทุก ๆ สี่ปี
ตรรกะที่เราจะนำไปใช้เพื่อค้นหาว่าปีที่กำหนดโดยผู้ใช้ผ่านคอนโซลเป็นการก้าวกระโดดหรือไม่ -
if (( year%400 == 0)|| (( year%4 == 0 ) &&( year%100 != 0)))
หากเป็นไปตามเงื่อนไขนี้ ปีที่กำหนดจะเป็นปีอธิกสุรทิน ไม่อย่างนั้นก็ไม่ใช่
ตัวอย่าง
ต่อไปนี้เป็นโปรแกรม C เพื่อตรวจสอบปีอธิกสุรทินโดยใช้เงื่อนไข if -
#include <stdio.h>
int main(){
int year;
printf("Enter any year you wish \n ");
scanf(" %d ", &year);
if (( year%400 == 0)|| (( year%4 == 0 ) &&( year%100 != 0)))
printf("\n %d is a Leap Year. \n", year);
else
printf("\n %d is not the Leap Year. \n", year);
return 0;
} ผลลัพธ์
เมื่อโปรแกรมข้างต้นทำงาน มันจะให้ผลลัพธ์ดังต่อไปนี้ −
Enter any year you wish 2045 2045 is not the Leap Year.