# C Program to compute the difference between two dates.

Write a C program to compute the difference between two dates.In this C Program, We check the date is valid or not and then calculating the No. of days of first date and second date from Jan 1 of first date, then subtract the smaller date from another. Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                      Happy Coding***********************************************************/#include<stdio.h>#include<math.h>#include<conio.h>void main(){    int day1,mon1,year1,day2,mon2,year2;    int ref,dd1,dd2,i;    clrscr();    printf("Enter first date  day, month, yearn");    scanf("%d%d%d",&day1,&mon1,&year1);    printf("Enter second date day, month, yearn");    scanf("%d%d%d",&day2,&mon2,&year2);    ref = year1;    if(year2<year1)    ref = year2;    dd1=0;    dd1=dater(mon1);    for(i=ref;i<year1;i++)    {        if(i%4==0)        dd1+=1;    }    dd1=dd1+day1+(year1-ref)*365;    dd2=0;    for(i=ref;i<year2;i++)    {        if(i%4==0)        dd2+=1;    }    dd2=dater(mon2)+dd2+day2+((year2-ref)*365);    printf("nn Difference between the two dates is %d days",abs(dd2-dd1));        getch();}int dater(x){ int y=0;    switch(x)    {        case 1: y=0; break;        case 2: y=31; break;        case 3: y=59; break;        case 4: y=90; break;        case 5: y=120;break;        case 6: y=151; break;        case 7: y=181; break;        case 8: y=212; break;        case 9: y=243; break;        case 10:y=273; break;        case 11:y=304; break;        case 12:y=334; break;        default: printf("Invalid Inputnnnn"); exit(1);    }    return(y);}`
`Read more Similar C ProgramsLearn C ProgrammingNumber System`

You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

To browse more C Programs visit this link
(c) www.c-program-example.com

# C Program to calculate the total execution time of a program.

C Program to calculate the total execution time of a program. Here we used the “time.h” preprocessor. In this program we used the clock_t variables start and end , They starts the time counter and ends the counter. Execution time of a program is useful to calculate the efficiency of the program.

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                      Happy Coding***********************************************************/#include<stdio.h>#include<time.h>int main() { int i; double total_time; clock_t start, end; start = clock();//time count starts  srand(time(NULL)); for (i = 0; i < 25000; i++)  {  printf("random_number[%d]= %dn", i + 1, rand()); } end = clock();//time count stops  total_time = ((double) (end - start)) / CLK_TCK;//calulate total time printf("nTime taken to print 25000 random number is: %f", total_time); return 0;}`
`Read more Similar C ProgramsLearn C ProgrammingNumber System`

You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

(c) www.c-program-example.com

# C Program to show Sleep() function example.

C Program to show Sleep() function example.
sleep() function stops the execution of the program, wherever its invoked or called. It takes the arguments in microseconds. In Windows we use Sleep() function i,e ‘S’, and for other systems it is sleep() function.
```/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
*                                  Happy Coding
***********************************************************/

#include <time.h>
#include <stdio.h>
#include <windows.h>
#include <conio.h>

int main()
{
printf("This is the message before sleep() function");
Sleep(1000); //1000 microsecond= 1 second will sleep...
printf("This is the message after 1 second");
getch();
return 0;
}

However, I have to remind you that the program may change a bit based on
what Operating system and compiler you are using.

```Learn C Programming
Number System```

You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

List of C Programs
(c) www.c-program-example.com

# C program to find the distance traveled at regular intervals of time given .

C program to find the distance traveled at regular intervals of time given the values of ‘u’ and ‘a’. The program should provide the flexibility to the user to select his own time intervals and repeat the calculations for different values of ‘u’ and ‘a’. Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                                  Happy Coding***********************************************************/#include <stdio.h>#include <math.h>void main() { int tim_intrval, counter, time; float accl, distance = 0, velos; clrscr(); printf(   "<===========PROGRAM TO CALCULATE TOTAL DISTANCE TRAVELED BY A VECHIAL===========>"); printf("nnntNO OF TIME INTERVALS : "); scanf("%d", &tim_intrval); for (counter = 1; counter <= tim_intrval; counter++) {  printf("nttAT T%d TIME(sec) : ", counter);  scanf("%d", &time);  printf("ttVELOCITY AT %d sec (m/sec) : ", time);  scanf("%f", &velos);  printf("ttACCLERATION AT %d sec (m/sec^2): ", time);  scanf("%f", &accl);  distance += (velos * time + (accl * pow(time, 2)) / 2); } printf(   "nnntTOTAL DISTANCE TRAVELLED BY VEHICLE IN %d INTERVALS OF TIME : %f",   tim_intrval, distance); getch();}`
`Read more Similar C ProgramsLearn C ProgrammingC Strings`

You can easily select the code by double clicking on the code area above.

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

(you can send this program to your friend using this button)

(c) www.c-program-example.com

# C Program to demonstrate time functions.

C Program to demonstrate time functions. time.h library function is used to get and manipulate date and time functions. Read more about C Programming Language .

`/************************************************************ You can use all the programs on  www.c-program-example.com* for personal and learning purposes. For permissions to use the* programs for commercial purposes,* contact [email protected]* To find more C programs, do visit www.c-program-example.com* and browse!* *                                  Happy Coding***********************************************************/#include <stdio.h>  /* NULL     */#include <time.h>  /* ctime, asctime   */main(){ time_t now;    /* define 'now'. time_t is probably   * a typedef */ /* Calender time is the number of   * seconds since 1/1/1970  */ now = time((time_t *)NULL);  /* Get the system time and put it   * into 'now' as 'calender time' */ printf("%s", ctime(&now));  /* Format data in 'now'    * NOTE that 'ctime' inserts a  * 'n' */ /*********************************************************************/ /* Here is another way to extract the time/date information */ time(&now); printf("%s", ctime(&now));  /* Format data in 'now'  */ /*********************************************************************/ {  struct tm *l_time;  l_time = localtime(&now);  /* Convert 'calender time' to    * 'local time' - return a pointer    * to the 'tm' structure. localtime   * reserves the storage for us. */  printf("%s", asctime(l_time)); } /*********************************************************************/ time(&now); printf("%s", asctime(localtime( &now  ))); /*********************************************************************/ {  struct tm *l_time;  char string[20];  time(&now);  l_time = localtime(&now);   strftime(string, sizeof string, "%d-%b-%yn", l_time);  printf("%s", string); }}`
`Read more Similar C ProgramsLearn C ProgrammingSimple C Programs`

You can easily select the code by double clicking on the code area above.