Find your day from your DOB?
Answers were Sorted based on User's Feedback
#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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Answer / wellwisher
@Rose2502 : interest and working hard is the only key to
success..practise well:)
Is This Answer Correct ? | 0 Yes | 0 No |
Predict the Output: int main() { int *p=(int *)2000; scanf("%d",2000); printf("%d",*p); return 0; } if input is 20 ,what will be print
How we print the table of 2 using for loop in c programing?
Write a single line c expression to delete a,b,c from aabbcc
#define square(x) x*x main() { int i; i = 64/square(4); printf("%d",i); }
4 Answers Google, HCL, Quick Heal, WTF,
What are the files which are automatically opened when a C file is executed?
main() { char name[10],s[12]; scanf(" \"%[^\"]\"",s); } How scanf will execute?
What is the output of the program given below main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
How to use power function under linux environment.eg : for(i=1;i<=n;i++){ pow(-1,i-1)} since it alerts undefined reference to 'pow'.
main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }
Program to Delete an element from a doubly linked list.
4 Answers College School Exams Tests, Infosys,
How we will connect multiple client ? (without using fork,thread)
void main() { void *v; int integer=2; int *i=&integer; v=i; printf("%d",(int*)*v); }