C Programming
- Print integer
- Add & subtract
- Odd & even
- Multiply & divide
- Check vowels
- Letter grade program
- Leap year program
- Sum of digits
- Prime numbers
- Sum of numbers
- Find factorial
- Fibonacci series
- Fibonacci triangle
- Number triangle
- Alphabet triangle
- Armstrong numbers
- Palindrome numbers
- Swap number
- Reverse number
- Decimal to binary
- Assembly code in C
- Matrix multiplication
- HCF & LCM
- nCr & nPr
- Print pattern
- Floyd’s triangle
- Pascal triangle
- Count digits
- Strong numbers
- Perfect numbers
- Sum of natural number
- Binary to decimal
- Decimal to octal
- Octal to decimal
- Binary to octal
- Octal to binary
- Add using pointer
- Bubble sort
- Insertion sort
- Selection sort
- Quick sort
- Binary search
- Linear search
- Largest element of array
- Smallest element of array
- Reverse Array
- Variable size & limit
- ASCII value of character
- Sum of array elements
- Number of element in array
- Merge two array
- Insert element in array
- Delete element from array
- Add two matrix
- Transpose matrix
- Print string
- Reverse string
- Delete vowels
- Sort string
- Remove spaces
- Swap string
- Random numbers
- Print date & time
- Print IP address
- Shut down computer
Writing leap year program in C
We will know about leap year program in C here. You may have know that leap year is the year which can be divisible by 400 and 4 but not divisible by 100. We can apply this logic to check that the given year is leap year or not. We can make a leap year program using if else statement or switch statement. Here in this article we will make several leap year program in using C programming language.
Checking leap year using if else in C
// Leap year program in C
#include <stdio.h>
int main(){
int year;
printf("Enter the year you want to check : ");
scanf("%d", &year);
if (year % 400 == 0){ // checking if it is divisible by 400
printf("\n%d is a leap year.\n", year);
}else if (year % 100 == 0){ // checking if it is divisible by 100
printf("\n%d is not a leap year.\n", year);
}else if (year % 4 == 0){ // checking if it is divisible by 4
printf("\n%d is a leap year.\n", year);
}else{
printf("\n%d is not a leap year.\n", year);
}
return 0;
}
Output of the leap year program:

Check leap year using switch statement
#include <stdio.h>
int main(){
int year;
printf("Enter the year you want to check : ");
scanf("%d", &year);
int makeInt = (year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0);
switch(makeInt){
case 1:
printf("Leap year.\n");
break;
default:
printf("Not leap year.\n");
}
return 0;
}
See the output
Enter the year you want to check : 2020
Leap year.
Process returned 0 (0x0) execution time : 5.803 s
Press any key to continue.
Previous page:Â Letter grade program in C
Next page:Â Sum of digits program in C