C program Leap year or not and Odd or Even

It is a program to find a year given by user is leap year or not. The input integer, year is read from user verified by modulus operator and condition statement. If the condition is satisfied, the year is leap year, otherwise it is not a leap year.


Year is leap or not

if the given year divided 4 and returns reminder 0, it is leap year, otherwise not leap year

             READ year
             reminder = year modulus 4
 
            if reminder == 0, 
                  PRINT it is leap year
            else 
               PRINT it is not leap year
            end 
   

Year is leap or not - C program

The C program finds a given year is leap or not

 
#include <stdio.h>
#include <string.h>

int main() {

   int year; int reminder=0;       
   printf ("\n Find a given year is Leap year or not ");
   
   printf("\n Enter a Year  :" );
   scanf("%d", &year);
   
   reminder  = year % 4;
   if (  !reminder ) {   
        printf("The year %d is leap ",year);    
   } else {
        printf("The year %d is not leap ",year);    
   }
       
   return 0;
}

 

Year is leap or not - C program Output

 Find a given year is Leap year or not
 Enter a Year
 2017

The year 2017 is not leap
Find a given year is Leap year or not
 Enter a Year
 2012

The year 2012 is leap


It is a program to find a number given by user is odd number or even number. The input integer is read from user verified by modulus operator and condition statement. If the condition is satisfied, the integer is a odd number, otherwise it is a even number.


Number is Odd or Even - pseudocode

if the given number divided 2 and returns reminder 1, it is a odd number, otherwise it is a even number

             READ number
             reminder = number modulus 2
 
            if reminder == 1, 
                  PRINT it is a odd 
            else 
               PRINT it is a even 
            end 
   

Number is Odd or Even -C program

The C program finds a given number is odd or even number

 

#include <stdio.h>
#include <string.h>

int main() {

   int decval; int reminder=0;       
   printf ("\n Find a given number is odd or even number ");
   
   printf("\n Enter a Decimal value :" );
   scanf("%d", &decval);
   
   reminder  = decval % 2;
   if (  reminder ) {   
        printf("The number %d is odd ",decval);    
   } else {
        printf("The number %d is even",decval);    
   }
       
   return 0;
}

 

Number is Odd or Even -C program output

Find a given number is odd or even number
  146
The number 146 is even

Find a given number is odd or even number
  127
The number 127 is odd


Download c program source code


Comments

Popular posts from this blog

Hexadecimal to Binary Conversion

Binary to Decimal conversion -Bitwise Left shift Operator

Convert Octal to Binary