Skip to main content

C Program to Check Leap Year

C program to check whether a year is leap year or not using if else statement.




     #include <stdio.h>

     int
main()

     {
      int year;
      printf("Enter a year: ");
      scanf("%d",&year);


      if(year%4 == 0)
      {
          if( year%100 == 0)   /* Checking for a century year */
          {
              if ( year%400 == 0)
                 printf("%d is a leap year.", year);
              else
                 printf("%d is not a leap year.", year);
          }
          else
             printf("%d is a leap year.", year );
      }
      else

         printf("%d is not a leap year.", year);


      return 0;
      }


 Output 1:

                                  Enter year: 1900
                                  1900 is not a leap year.


Output 2:


                                   Enter year: 2012
                                   2012 is a leap year.



Comments

Popular posts from this blog

Fibonacci series in c

Fibonacci series in c Fibonacci series in c programming: c program for Fibonacci series without and with recursion. Using the code below you can print as many numbers of terms of series as desired. Numbers of Fibonacci sequence are known as Fibonacci numbers. First few numbers of series are 0, 1, 1, 2, 3, 5, 8 etc, Except first two terms in sequence every other term is the sum of two previous terms, For example 8 = 3 + 5 (addition of 3, 5). This sequence has many applications in mathematics and Computer Science. Fibonacci series in c using for loop /* Fibonacci Series c language */   #include <stdio.h>   int main ( ) { int n , first = 0 , second = 1 , next , c ;   printf ( "Enter the number of terms \n " ) ; scanf ( "%d" ,& n ) ;   printf ( "First %d ...

Sum, Average and Standard deviation in c

 Sum, Average and Standard deviation Write a function that receives 5 integers and returns the sum, average and standard deviation of these numbers. Call this function from main( ) and print the results in main( ). #include <stdio.h> void stat(int a,int b,int c,int d,int e,int *su,float *av,float *std) void main() { clrscr(); float ave,sd; int a,b,c,d,e,sum; printf( "\nInput 5 integers\n" ); scanf( "\n%d\n%d\n%d\n%d\n%d" ,&a,&b,&c,&d,&e);   stat(a,b,c,d,e,&sum,&ave,&sd); printf( "\nThe sum is %d\nThe average is %f\nThe standard deviation is %f" ,sum,ave,sd); } void stat(int a,int b,int c,int d,int e,int *su,float *av,float *std) { * su=a+b+c+d+e; * av= * su/5; * std=sqrt(((((a-*av)*(a-*av))+((b-*av)*(b-*av))+((c-*av)*(c-*av)))/5.0); }

Program to reverse the array.

Program to reverse the array. #include <stdio.h> void main() {    int n, c, a[100],;    printf( "Enter the number of elements in array\n" );    scanf( "%d" , &n);    printf( "Enter the array elements\n" );      for (c = 0; c < n ; c++)       scanf( "%d" , & a[c] );       pdrintf( "Reversed array is \n" );       for (c=n;c>=0;c--)    printf( "%5d" , a[c] );    getch(); } Output: