In this tutorial, we will learn how to write a program to check the given year is leap year or not. We will write a program by using if else statement that find the given year is leap year.
Solution:
- In this program we will use two header files.
- In this program we will use one variable year.
- We declared this variable year in int data type.
- Then we will enter the value of year.
- We will use if else statement with one conditions which is (year%4==0).
- And after it we will print the statement or body.
- When we use these statement the condition execute own statement.
- If the condition is false the else statement will be executed.
C program code
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
printf("\n Enter a year=");
scanf("%d",&year);
if(year%4==0)
{
printf("\n The given year is a leap year");
}
else
{
printf("\n The given year is not a leap year");
}
getch();
}
Output 1:
Output 2:
We will write a program by using if else statement that find the given year is leap year or not.we will use one variable year and declared it in int data type.
Then we will use if else statement for use condition. And find the leap year or not.
In the first compiler will check the if condition. If the condition is true then the statement of if will be executed otherwise else statement will be executed.
I hope that you understand everything easily.If you have any problem or question so you write a comment and follow me on this blog and my Facebook page and on Instagram.Share the post.
No comments:
Post a Comment