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() { char a[4]="HELL"; printf("%s",a); }

3 Answers   Wipro,


write a c program to Create a registration form application by taking the details like username, address, phone number, email along with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 5 users and display the details. In place of password display “****”. (Use Structures).

0 Answers   CDAC, College School Exams Tests,


main(int argc, char *argv[]) { (main && argc) ? main(argc-1, NULL) : return 0; } a. Runtime error. b. Compile error. Illegal syntax c. Gets into Infinite loop d. None of the above

4 Answers   HCL, LG,


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  


how to check whether a linked list is circular.

11 Answers   Microsoft,






How to return multiple values from a function?

7 Answers  


How we print the table of 3 using for loop in c programing?

7 Answers  


Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it. You are allowed to destroy the array if you like.

21 Answers   ABC, eBay, Goldman Sachs, Google, HUP, Microsoft, TATA,


What are the files which are automatically opened when a C file is executed?

1 Answers  


How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?

0 Answers  


main() { while (strcmp(“some”,”some\0”)) printf(“Strings are not equal\n”); }

1 Answers  


&#8206;#define good bad main() { int good=1; int bad=0; printf ("good is:%d",good); }

2 Answers  


Categories