C Program to check leap year using ternary operator

leap year program in c using ternary operator
Leap year program in c using ternary operator
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:
Output of leap year program in c using ternary operator



Algorithm:

  1. Start
  2. declare int year
  3. Print "Enter The Year"
  4. Accept value for "year"
  5. Check year%4==0 and year%100!=0
  6. if true go to step 8
  7. if false go to step 9
  8. print "LEAP YEAR"
  9. print "COMMON YEAR"
  10. Stop 

Flowchart: 
flowchart of leap year program in c using ternary operator





No comments:

Post a Comment

Feel free to ask us any question regarding this post