Skip to main content

Program will accept Year,Month and Date from the user and will display the day of the month.

#include<stdio.h>
#include<conio.h>
#include<math.h>

int isdatevalid(int month, int day, int year)
{
if (day <= 0) return 0 ;
switch( month )
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: if (day > 31) return 0 ; else return 1 ;
case 4:
case 6:
case 9:
case 11: if (day > 30) return 0 ; else return 1 ;
case 2:
if ( day > 29 ) return 0 ;
if ( day < 29 ) return 1 ;

else return 0 ;
}
return 0 ;
}
//------------------------------------------------
int fm(int date, int month,int year)
{
int fmonth,leap;

//leap function 1 for leap & 0 for non-leap

if((year%100==0) && (year%400!=0))
leap=0;
else if(year%4==0)
leap=1;
else
leap=0;

fmonth=3+(2-leap)*((month+2)/(2*month))+(5*month+month/9)/2;
//f(m) formula

fmonth = fmonth % 7; //bring it in range of 0 to 6

return fmonth;
}

//----------------------------------------------
int day_of_week(int date, int month, int year)
{
int dow; //day of week

int YY = year % 100;
int century = year / 100;

printf("nDate: %d/%d/%dnn",date,month,year);

dow = 1.25 *  YY + fm(date,month,year) + date - 2*( century % 4);
//function of weekday for Gregorian

dow = dow % 7; //remainder on division by 7

switch (dow)
{
case 0:
printf("weekday = Saturday");
break;
case 1:
printf("weekday = Sunday");
break;
case 2:
printf("weekday = Monday");
break;
case 3:
printf("weekday = Tuesday");
break;
case 4:
printf("weekday = Wednesday");
break;
case 5:
printf("weekday = Thursday");
break;
case 6:
printf("weekday = Friday");
break;
default:
printf("Incorrect data");
}
return 0;
}
//------------------------------------------
void main()
{
int date,month,year;
clrscr();

printf("Enter the year ");
scanf("%d",&year);

printf("Enter the month ");
scanf("%d",&month);

printf("Enter the date ");
scanf("%d",&date);

day_of_week(date,month,year);

getch();
}



Output :




Enter the year 2012
Enter the month 02
Enter the date 29

Date: 29/2/2012

weekday = Wednesday



Comments

Popular posts from this blog

WAP to calculate the monthly telephone bills as per the following rule: Minimum Rs. 200 for upto 100 calls. Plus Rs. 0.60 per call for next 50 calls. Plus Rs. 0.50 per call for next 50 calls. Plus Rs. 0.40 per call for any call beyond 200 calls.

  #include<iostream.h> #include<conio.h> void main() { int calls; float bill; cout<<" Enter number of calls : "; cin>>calls; if (calls<=100) bill=200; else if (calls>100 && calls<=150) { calls=calls-100; bill=200+(0.60*calls); } else if (calls>150 && calls<=200) { calls=calls-150; bill=200+(0.60*50)+(0.50*calls); } else { calls=calls-200; bill=200+(0.60*50)+(0.50*50)+(0.40*calls); } cout<<" Your bill is Rs. "<<bill; getch(); }   Output: Enter number of calls : 190 Your bill is Rs.250

C++ Program to define a Class BOOK and accessing member function using its object.

  #include<iostream.h> #include<stdio.h> #include<conio.h> class BOOK { int BOOKNO; char BOOKTITLE[20]; float PRICE; void TOTAL_COST( int N) { float tcost; tcost=PRICE*N; cout<<tcost; } public : void INPUT() { cout<<" Enter Book Number "; cin>>BOOKNO; cout<<" Enter Book Title "; gets(BOOKTITLE); cout<<" Enter price per copy "; cin>>PRICE; } void PURCHASE() { int n; cout<<" Enter number of copies to purchase "; cin>>n; cout<<" Total cost is "; TOTAL_COST(n); } }; void main() { BOOK obj; obj.INPUT(); obj.PURCHASE(); getch(); }

Addition of Two Number using servlet and jsp

index.jsp <%@page contentType="text/html" pageEncoding="UTF-8"%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > < html > < head > < meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" > < title > JSP Page </ title > </ head > < body bgcolor ="yellow" > < center >< h1 > Addition of Two Number </ h1 ></ center > < form action =" additionservlet " method ="post" > < table border ="0" width ="100" align ="center" > < tr > < td > First Number </ td > < td >< input type ="text" name ="txtnum1" value ="" /></ td > ...