ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
Find your day from your DOB?
 Question Submitted By :: Solidcube
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Find your day from your DOB?
Answer
# 1

#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 ?    0 Yes 0 No
Raghuram.A
 
  Re: Find your day from your DOB?
Answer
# 2
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 ?    0 Yes 0 No
Saurabh Shah
 
 
 
  Re: Find your day from your DOB?
Answer
# 3
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 ?    0 Yes 0 No
Raghuram.a
 
  Re: Find your day from your DOB?
Answer
# 4
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
Abraham
 
  Re: Find your day from your DOB?
Answer
# 5
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
Raghuram.A
 
  Re: Find your day from your DOB?
Answer
# 6
@Raghu..

good job.. :-)
thanks for the code.. :-)
 
Is This Answer Correct ?    0 Yes 1 No
Shruti
 
  Re: Find your day from your DOB?
Answer
# 7
using date structures
 
Is This Answer Correct ?    0 Yes 1 No
Ganesh
 
  Re: Find your day from your DOB?
Answer
# 8
pleasse refer calender book....

if u feel difficult to find your day of your date of birth
call me...i will help u!
                         by prof.muthu  M.C.A PHD 
                         PH:9962940220
 
Is This Answer Correct ?    0 Yes 4 No
Prof.muthu
 
  Re: Find your day from your DOB?
Answer
# 9
who is this moron prof.muthu....y the hell r u writing such
nonsense...we all know to solve by ur methods..jus stop
writing such things or GO TO HELL.
 
Is This Answer Correct ?    0 Yes 1 No
Hates Prof.muthu
 
  Re: Find your day from your DOB?
Answer
# 10
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
Apygcpr
 
  Re: Find your day from your DOB?
Answer
# 11
<a href="http://itywyw.co.cc/blog3/1916.html ">jlejnl</a>  http://itywyw.co.cc/2125.html  <a href="http://itywyw.co.cc/blog3/1916.html ">jlejnl</a>  doctor http://itywyw.co.cc/2125.html jbnvnbh doctor  http://itywyw.co.cc/2125.html jbnvnbh
 
Is This Answer Correct ?    0 Yes 2 No
Wfiasea
 
  Re: Find your day from your DOB?
Answer
# 12
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
Xisgjm
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
main() { extern int i; i=20; printf("%d",i); }  1
void main () { int x = 10; printf ("x = %d, y = %d", x,--x++); } a. 10, 10 b. 10, 9 c. 10, 11 d. none of the above HCL1
Which version do you prefer of the following two, 1) printf(“%s”,str); // or the more curt one 2) printf(str);  1
#include<stdio.h> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }  1
main() { int i; clrscr(); printf("%d", &i)+1; scanf("%d", i)-1; } a. Runtime error. b. Runtime error. Access violation. c. Compile error. Illegal syntax d. None of the above HCL1
main() { static int var = 5; printf("%d ",var--); if(var) main(); }  1
void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(“%d”, i); }  1
main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); }  1
main() { void swap(); int x=10,y=8; swap(&x,&y); printf("x=%d y=%d",x,y); } void swap(int *a, int *b) { *a ^= *b, *b ^= *a, *a ^= *b; }  1
What is the output for the following program main() { int arr2D[3][3]; printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) ); }  1
main() { int i; clrscr(); for(i=0;i<5;i++) { printf("%d\n", 1L << i); } } a. 5, 4, 3, 2, 1 b. 0, 1, 2, 3, 4 c. 0, 1, 2, 4, 8 d. 1, 2, 4, 8, 16 HCL1
Write a program that find and print how many odd numbers in a binary tree  1
void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }  1
main() { int i=400,j=300; printf("%d..%d"); }  1
#define assert(cond) if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort()) void main() { int i = 10; if(i==0) assert(i < 100); else printf("This statement becomes else for if in assert macro"); }  1
What are the files which are automatically opened when a C file is executed?  1
main() { float f=5,g=10; enum{i=10,j=20,k=50}; printf("%d\n",++k); printf("%f\n",f<<2); printf("%lf\n",f%g); printf("%lf\n",fmod(f,g)); }  1
What is the output for the program given below typedef enum errorType{warning, error, exception,}error; main() { error g1; g1=1; printf("%d",g1); }  1
main() { struct date; struct student { char name[30]; struct date dob; }stud; struct date { int day,month,year; }; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year); }  1
#define square(x) x*x main() { int i; i = 64/square(4); printf("%d",i); }  1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com