• Breaking News

    Funny Coder

    Funny coder is an open source web for interested programmer. It is a programming environment.It's a way where you can code with fun.

    Friday, April 22, 2016

    Check the year is leap year or not C program


    Check the year is leap year or not C program 

    /*
    Name   : C source program
    Author : Funny Coder(Maniruzzman Akash)
    It's a free code. You can use it anywhere
    */


    #include <stdio.h>
    int main(){
          int year;
          printf("\nEnter any year to check: ");
          scanf("%d", &year);
          if(year % 4 == 0)      //Check devided by 4 or not
          {
              if( year % 100 == 0) 
              {
                  if ( year%400 == 0)
                     printf("%d is a leap year.\n", year);
                  else
                     printf("%d is not a leap year.\n", year);
              }
              else
                 printf("%d is a leap year.\n", year );
          }
          else{
          printf("%d is not a leap year.\n", year);
     }
             
          return 0;
    }

    Leap year C program run

    Leap year C program run


    Someone think that only devided 4 is a leap year. But that's false. That code is :

    #include <stdio.h>
    int main(){
          int year;
          printf("\nEnter any year to check: ");
          scanf("%d", &year);
          if(year % 4 == 0)    
     //Check devided by 4 or not
          {
            printf("%d is a leap year.\n", year );
          }else{
          printf("%d is not a leap year.\n", year);
     }
            
          return 0;
    }

    The error out put of this code is : 

    Error output leap year in C


    But 3000 is never be a leap year. So,follow the first code.




    No comments:

    Post a Comment

    Fashion

    Beauty

    Travel