This is a C program to check whether entered year is leap year or a common year using ternary or Conditional operator
Understand the syntax:
Condition ? Statement if true : Statement if false ;
if given condition is true then the statement in true part will be executed and if condition is false then statement in false part will be executed and whichever part will be executed that will be the value of whole expression.
Program:
/**
C program to check leap year using ternary operator by SlashMyCode.com
**/
#include <stdio.h>
int main()
{
int year;
printf("Enter the year: ");
scanf("%d", &year);
(year%4==0 && year%100!=0) ? printf("LEAP YEAR") : printf("COMMON YEAR");
return 0;
}
Output:
Algorithm:
- Start
- declare int year
- Print "Enter The Year"
- Accept value for "year"
- Check year%4==0 and year%100!=0
- if true go to step 8
- if false go to step 9
- print "LEAP YEAR"
- print "COMMON YEAR"
- Stop
Flowchart:
No comments:
Post a Comment
Feel free to ask us any question regarding this post