write a program which will count occurance of a day between
two dates.



write a program which will count occurance of a day between two dates...

Answer / abdul

//calculate num of date bet two dates.
#include<stdio.h>
#include<conio.h>
struct day
{
int date;
int month;
int year;
}x1,x2;
void main()
{
int n_day=0;
clrscr();
printf("\nenter date month and year for x1::");
scanf("%d%d%d",&x1.date,&x1.month,&x1.year);
printf("\nenter date month and year for x2::");
scanf("%d%d%d",&x2.date,&x2.month,&x2.year);
if(x1.year>x2.year)
n_day=n_day+(x1.year-x2.year)*365;
else
n_day=n_day+(x2.year-x1.year)*365;
if(x1.month>x2.month)

n_day=n_day+(x1.month-x2.month)*30;
else
n_day=n_day+(x2.month-x1.month)*30;
if(x1.date>x2.date)
n_day=n_day+(x1.date-x2.date);
else
n_day=n_day+(x2.date-x1.date);
printf("\n\n no. of days between entered two days=%d",n_day);
getch();
}

Is This Answer Correct ?    20 Yes 4 No

Post New Answer

More C Interview Questions

What are runtime error?

0 Answers  


how many keywords do C compile?

7 Answers   Microsoft, Practical Viva Questions,


#include main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j: printf("BAD"); break; } }

6 Answers   ME,


how to set Nth bit of a variable?

1 Answers  


What are Macros? What are its advantages and disadvantages?

0 Answers   TCS,






what is memory leak?

3 Answers  


Why the use of alloca() is discouraged?

2 Answers   Oracle,


What is the default value of local and global variables in c?

0 Answers  


What are the difference between a free-standing and a hosted environment?

0 Answers   Infogain,


Explain what is a const pointer?

0 Answers  


Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?

0 Answers   Infosys,


Write a program to swap two numbers without using third variable?

0 Answers  


Categories