PROJECT: Print WeekDays When Number Enter 1 to 7.

Learn and Trouble Shoot Problems Related to C-Language here.

PROJECT: Print WeekDays When Number Enter 1 to 7.

Unread postby rajeevmahura » Thu May 22, 2008 6:00 pm

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter Your Choice 1 to 7:- ");
scanf("%d",&n);
switch(n)
{
case 1 : printf("\tSunday");break;
case 2 : printf("\tMonday");break;
case 3 : printf("\tTuesday");break;
case 4 : printf("\tWednesday");break;
case 5 : printf("\tThursday");break;
case 6 : printf("\tFriday");break;
case 7 : printf("\tSaturday");break;
default : printf("\n\tEnter Number is Invalid ");
}
getch();
}
---------------------------------------------
Input: n=4
Output: Wednesday
--Regards--
Rajeev Mahura
Servers & Storage Professional
http://about.me/rajeevmahura
User avatar
rajeevmahura
 
Posts: 144
Joined: Tue May 20, 2008 5:22 pm
Location: Bangalore | New Delhi
Full Name: Rajeev Mahura
Date Of Birth: 15 Jan 1984
Address: New Delhi
Profession: DOEACC Trainer
DOEACC Center: DOEACC DELHI
Mobile No: 0

Re: PROJECT: Print WeekDays When Number Enter 1 to 7.

Unread postby manojthesingham » Tue Sep 01, 2009 8:35 pm

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

char *wday[]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};
int mday[]={0,31,59,90,120,151,181,212,243,273,304,334,365};
typedef enum{sunday=0,monday,tuesday,wednesday,thursday,friday,saturday}WEEK;
typedef enum{false,true}boolean;
typedef struct{int year,month,day;}DATE;


boolean isLeapYear(int x)
{
if((x%400)==0)
return true;
if((x%100)==0)
return false;
if((x%4)==0)
return true;
return false;
}

const char * dayOfWeek()
{
DATE date;
int y,d,odd=0,t1,t2;

scanf("%d",&(date.day), printf("Day : "));
scanf("%d",&(date.month),printf("Month : "));
scanf("%d",&(date.year), printf("Year : "));

d = isLeapYear(date.year)?(mday[(date.month-1)] +1):mday[(date.month-1)];
d += date.day;

y = date.year-1;
y%=400;
odd+=(y/300);
y%=300;
odd+=3*(y/200);
y%=200;
odd+=5*(y/100);
y%=100;
t1 = y/4; /*remaining leap years*/
t2 = y-t1; /* remaining years*/
odd+=(t1*2)+t2;
odd%=7;
odd = (odd+d%7)%7;
return wday[odd];
}

int main(int argc,char **argv)
{
printf("%s",dayOfWeek());
getch();
return 1;
}
/*
Day : 31
Month : 7
Year : 1989
monday
*/
If world is running, then I am idle..
If I am idle, then the world is running
User avatar
manojthesingham
 
Posts: 15
Joined: Tue Sep 01, 2009 5:39 am
Location: Coimbatore,Tamilnadu
Full Name: manoj
Date Of Birth: 31 Jul 1989
Address: Coimbatore18Tamilnadu
Mobile No: 0


Return to C-Language

Who is online

Users browsing this forum: No registered users and 1 guest

cron