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 |
main() { float me = 1.1; double you = 1.1; if(me==you) printf("I love U"); else printf("I hate U"); }
char *someFun1() { char temp[ ] = “string"; return temp; } char *someFun2() { char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’}; return temp; } int main() { puts(someFun1()); puts(someFun2()); }
code of a program in c language that ask a number and print its decremented and incremented number.. sample output: input number : 3 321123
Write a routine that prints out a 2-D array in spiral order
main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); }
void main() { static int i=i++, j=j++, k=k++; printf(“i = %d j = %d k = %d”, i, j, k); }
void main() { int i=5; printf("%d",i+++++i); }
posted by surbhi just now main() { float a = 5.375; char *p; int i; p=(char*)&a; for(i=0;i<=3;i++) printf("%02x",(unsigned char) p[i]); } how is the output of this program is :: 0000ac40 please let me know y this output has come
programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h
main() { int i = 0xff ; printf("\n%d", i<<2); } a. 4 b. 512 c. 1020 d. 1024
Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list)
3 Answers Disney, Google, ZS Associates,
void main() { int *i = 0x400; // i points to the address 400 *i = 0; // set the value of memory location pointed by i; }