The Artima Developer Community
Sponsored Link

Java Buzz Forum
C program to find leap year using conditional operator

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
C program to find leap year using conditional operator Posted: May 15, 2017 1:10 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: C program to find leap year using conditional operator
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
  • We have already seen how to check leap year or not using C program here
  • Now we need to find out a leap year by using conditional operator using C programming language.
  • expression ? value1 : value2
  • if expression is true then it picks value1 else value2.
  • Let us see an example C program to check a year is leap year or not by using conditional operator.



Program #1: Write a C program to find leap year using conditional operator without using any function and loops.


  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(){
  5.     
  6.     int year;
  7.     printf("Enter a year to check if it is a leap year or not \n");
  8.     scanf("%d", &year);
  9.  
  10.    
  11.     (year%4==0 && year%100!=0) ? printf("Leap Year") :
  12.         (year%400 ==0 ) ? printf("Leap Year") : printf("not a leap year");
  13.         
  14.    getch();
  15.     
  16. }

Output:


  1. Enter a year to check if it is a leap year or not
  2. 2012
  3. Leap Year


leap year in c conditional operator

Read: C program to find leap year using conditional operator

Topic: Java Tutorial: Generics in java | Java Generics [Generic raw type] Previous Topic   Next Topic Topic: 57% off Anker PowerCore Fusion 5000 2-in-1 Portable Charger and Wall Charger - Deal Alert

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use