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

main() { extern int i; i=20; printf("%d",i); }

1 Answers   Value Labs,


main() { char *p="GOOD"; char a[ ]="GOOD"; printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), strlen(p)); printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a)); }

1 Answers  


void main() { if(~0 == (unsigned int)-1) printf(“You can answer this if you know how values are represented in memory”); }

1 Answers  


main() { int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }

3 Answers   GNITC,


How to read a directory in a C program?

4 Answers  






can u give me the c codings for converting a string into the hexa decimal form......

1 Answers  


main(){ unsigned int i; for(i=1;i>-2;i--) printf("c aptitude"); }

2 Answers  


write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30

0 Answers  


How will u find whether a linked list has a loop or not?

8 Answers   Microsoft,


What is data _null_? ,Explain with code when u need to use it in data step programming ?

0 Answers   Abbott,


# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }

1 Answers  


int a=1; printf("%d %d %d",a++,a++,a); need o/p in 'c' and what explanation too

1 Answers  


Categories