[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 379: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 678: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 678: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 678: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 678: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/session.php on line 1042: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
DOEACC FORUM • View topic - PROJECT: Print WeekDays When Number Enter 1 to 7.
Page 1 of 1

PROJECT: Print WeekDays When Number Enter 1 to 7.

Unread postPosted: Thu May 22, 2008 6:00 pm
by rajeevmahura
#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

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

Unread postPosted: Tue Sep 01, 2009 8:35 pm
by manojthesingham
#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
*/