Find your day from your DOB?

Answers were Sorted based on User's Feedback



Find your day from your DOB?..

Answer / raghuram.a



#include<iostream.h>
#include<conio.h>
int leap(int y)
{
if(y%4==0&&y%100!=0||y%400==0)
return 1;
else
return 0;
}
main()
{
int d,m,y,i,rem;
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
long int days=0;
clrscr();
cout<<"enter date in dd/mm/yyyy format:";
cin>>d>>m>>y;
for(i=1;i<y;i++)
if(leap(i))
days+=366;
else
days+=365;
for(i=1;i<m;i++)
if(leap(y)&&i==2)
days+=29;
else
days+=a[i-1];
days+=d;
rem=days%7;
switch(rem)
{case 1:cout<<"monday";
break;
case 2:cout<<"tuesday";
break;
case 3:cout<<"wedday";
break;
case 4:cout<<"thursday";
break;
case 5:cout<<"friday";
break;
case 6:cout<<"saturday";
break;
case 0:cout<<"sunday";

}
getch();
return 0;
}

Is This Answer Correct ?    2 Yes 0 No

Find your day from your DOB?..

Answer / saurabh shah

Hey buddy wrong program....!!!

if you check with DOB : 16/4/1985 OR 16/04/1985

its showing Friday...

But if you check then right answer should be Tuesday ...

Is This Answer Correct ?    1 Yes 0 No

Find your day from your DOB?..

Answer / raghuram.a

No..it's giving Tuesday only..U enter 16 4 1985 n press enter.
It will show Tuesday only..Logic is correct.I made a mistake
by telling to enter date in dd/mm/yyyy format..but u just
enter date in dd mm yyyy format(space between dd,mm and
yyyy)..u will get correct ans.

Raghuram.A

Is This Answer Correct ?    1 Yes 0 No

Find your day from your DOB?..

Answer / abraham

Hi Raghu, thanks for your program.
can you try 29th of feb 1983 (29/02/1983). Actually such a
date is not present. But gives Tuesday.
May be you like to correct it.

Is This Answer Correct ?    0 Yes 0 No

Find your day from your DOB?..

Answer / raghuram.a

Well..Abraham..I am not checking for invalid dates in that
program.
Here is the program that u want..

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

int leap(int y)
{
if(y%4==0&&y%100!=0||y%400==0)
return 1;
else
return 0;
}


int valid(int dd,int mm,int yy)
{
if(dd>31||dd<1||mm>12||mm<1||yy<0)
return 0;
if(mm<8)
if(mm%2==0&&dd>30)
return 0;
if(mm>=8)
if(mm%2!=0&&dd>30)
return 0;
if(mm==2)
{
if(yy%4==0&&dd>29)
return 0;
else
if(yy%4!=0&&dd>28)
return 0;
}
return 1;
}
main()
{
int d,m,y,i,rem;
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
long int days=0;
clrscr();
cout<<"enter date in dd m yyyy format:";
scanf("%d %d %d",&d,&m,&y);
if(!valid(d,m,y))
{
cout<<"\nInvalid date";
getch();
return 0;
}

for(i=1;i<y;i++)
if(leap(i))
days+=366;
else
days+=365;
for(i=1;i<m;i++)
if(leap(y)&&i==2)
days+=29;
else
days+=a[i-1];
days+=d;
rem=days%7;
switch(rem)
{
case 1:cout<<"monday";
break;
case 2:cout<<"tuesday";
break;
case 3:cout<<"wedday";
break;
case 4:cout<<"thursday";
break;
case 5:cout<<"friday";
break;
case 6:cout<<"saturday";
break;
case 0:cout<<"sunday";
}
getch();
return 0;
}

Is This Answer Correct ?    0 Yes 0 No

Find your day from your DOB?..

Answer / apygcpr

epidemiologist http://ygosepij.co.cc/3159.html xxpylt epidemiologist http://ygosepij.co.cc/3159.html http://ygosepij.co.cc/3159.html xxpylt <a href="http://cyhusi.co.cc/131.html ">hyalwr</a> <a href="http://cyhusi.co.cc/131.html ">hyalwr</a>

Is This Answer Correct ?    0 Yes 0 No

Find your day from your DOB?..

Answer / xisgjm

http://favevuzu.co.cc/blog21/931.html yqfrsdn <a href="http://favevuzu.co.cc/blog11/4704.html ">hoiimc</a> <a href="http://favevuzu.co.cc/blog11/4704.html ">hoiimc</a> optometrist http://favevuzu.co.cc/blog21/931.html yqfrsdn optometrist http://favevuzu.co.cc/blog21/931.html

Is This Answer Correct ?    0 Yes 0 No

Find your day from your DOB?..

Answer / rose2502

@raghuram : you r too gud..thnx for the code..i m a student of class 12th and i have grt interest in computer language...but it seems i will never be able to acquire such a deepness in this subject :-(..

Is This Answer Correct ?    0 Yes 0 No

Find your day from your DOB?..

Answer / wellwisher

@Rose2502 : interest and working hard is the only key to
success..practise well:)

Is This Answer Correct ?    0 Yes 0 No

Find your day from your DOB?..

Answer / saumya

@raghuram:thnx 4 ur advice..i vl definitely follow it..bt seriously i m impressed wid ur deep knowledge in programming..i too want to be like u.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Code Interview Questions

print a semicolon using Cprogram without using a semicolon any where in the C code in ur program!!

35 Answers   Tata Elxsi, TCS, VI eTrans,


Develop a routine to reflect an object about an arbitrarily selected plane

0 Answers  


void main() { printf(“sizeof (void *) = %d \n“, sizeof( void *)); printf(“sizeof (int *) = %d \n”, sizeof(int *)); printf(“sizeof (double *) = %d \n”, sizeof(double *)); printf(“sizeof(struct unknown *) = %d \n”, sizeof(struct unknown *)); }

1 Answers  


A program that will create a movie seat reservation. The program will display the summary seats and its status. The user will be ask what seat no. to be reserved, then it will go back again to the summary to display the updated seat status. If the seat no. is already reserved then it will prompt an error message. And also if the input seat no is out of range then it will also prompt an error message. The program is continuously running. Termination of the program will depends on how the programmer will apply. Sample output: Movie Seats Reservation Summary of Seats: Seat 1: Available Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 1 Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 6 The Seat no. is out of range! Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 1 The Seat no. is already reserved! Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 0 GoodBye... Thank You!!!

0 Answers  


main() { int i=4,j=7; j = j || i++ && printf("YOU CAN"); printf("%d %d", i, j); }

1 Answers  






#include <stdio.h> #define a 10 main() { #define a 50 printf("%d",a); }

2 Answers  


main() { printf("%x",-1<<4); }

3 Answers   HCL, Sokrati, Zoho,


main() { unsigned int i=65000; while(i++!=0); printf("%d",i); }

1 Answers  


How to access command-line arguments?

4 Answers  


main() { int i=10; i=!i>14; Printf ("i=%d",i); }

1 Answers  


respected sir, i did my MCA in 2013 when i am going to attend to an interview i was asked about my project how will i explain my project could please help me in this and my project title is "Social Networking Site For Social Responsibility"

1 Answers   Genpact, Ozdocs,


Cluster head selection in Wireless Sensor Network using C programming language.

0 Answers  


Categories