Wednesday, 9 March 2016

WAP ACCEPT ANY YEAR AS INPUT AND CHECK IF IT IS LEAP YEAR OR NOT

#include<stdio.h>
main()
{
int year;
printf("Enter a year ");
scanf("%d",&year);
if((year%4==0)&&(year%100!=0)||(year%400==0))
printf("%d is a leap year",year);
else
printf("%d is not a leap year",year);
}

ASSIGNMENT 2)

TO DEMONSTRATE USE OF DECISION MAKING STATEMENTS SUCH AS if AND if-else

You should read following topics before starting this exercise

1. Different types of decision making statements available in C.
2. Syntax for this statements.

i   )  if statements
     
   Syntax =  if (condition)
                   {
                    statement;
                    }

ii  ) if-else
   
   Syntax =  if (condition)
                   {
                    statement;
                    }
                    else
                    {
                    statement;
                    }

iii ) Nested if
   
                   if (condition)
                   {
                            if (condition)
                                          { statement; }
                            else
                                          { statement; }
                    }
                    else
                    {
                            if (condition)
                                          { statement; }
                            else
                                          { statement; }
                    }


No comments:

Post a Comment