Friday, 28 February 2014

Write a C program for implementing the Special operators


Write a C program for implementing the Special operators

 Source code:

  #include <stdio.h>

  int main()

{

   char feb;

   int days;

   printf("Enter l if the year is leap year otherwise enter 0: ");

   scanf("%c",&feb);

   days=(feb=='l')?29:28;

   /*If test condition (feb=='l') is true, days will be equal to 29. */

   /*If test condition (feb=='l') is false, days will be equal to 28. */

   printf("Number of days in February = %d",days);

   return 0;

}

Output:

Enter l if the year is leap year otherwise enter n: l

Number of days in February = 29


No comments: