Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Thursday, 2 June 2016

PROBLEM 9:
Mr. Bhola is not aware of Gregorian calendar dates. However, he knows that date is in the format ddmmyyyy. You are to Write a C Program for Mr. Bhola which he can run and determine whether a certain 8 digit number is a valid date or not. If date is valid print valid date, else print invalid.


CODE:
#include<stdio.h>
main ()
{
int value,year,date,month,divide1,divide;
printf("Enter date:");
scanf("%d",&value);
year=value%10000;
divide=(value-(value%10000))/10000;
month=divide%100;
divide1=(divide-(divide%100))/100;
date=divide1%100;

if (date<31 && month==4 || month==6 || month==9 || month==11)
        {
          printf("valid");

        }
else if(date>=1 && date<=31 && month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
        {
          printf("valid");
        }
else if(date==29 && month==2 && year%4==0)
        {
         printf("valid");
        }
else if(date>=1 && date<=28 && month==2)
        {
          printf("valid");
        }
else
        {
         printf("invalid");
        }
return 0;

}
Program Output:
28-03-2012
valid








For more problems click here

1 comment: