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

Is there a way to compare two structure variables?

0 Answers  


Add Two Numbers Without Using the Addition Operator

0 Answers  


Why isnt any of this standardized in c?

0 Answers  


What is the memory allocated by the following definition ? int (*x)[10];

4 Answers   ADITI, Wipro,


12344321 123 321 12 21 1 1 how i print this program??

5 Answers   DSR Management, Winit,






give an example of type casting by a simple c program

2 Answers   TCS,


why we wont use '&' sing in aceesing the string using scanf

0 Answers   HCL,


Why pointers are used?

0 Answers  


int i[2], j; int *pi;i[0] = 1; i[1] = 5; pi = i; j = *pi + 1 + *(pi + 1)Value of j after execution of the above statements will be a) 7 b) 6 c) 4 d) pointer

0 Answers  


While(1) { } when this loop get terminate is it a infinite loop?

5 Answers  


write a program for even numbers?

19 Answers   TCS,


Is reference used in C?

1 Answers  


Categories