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.
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<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 Programs
Learn C Programming

Number System

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

To get regular updates on new C programs, you can Follow @c_program

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

our page!

Share this program with your Facebook friends now! by liking it

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

Like to get updates right inside your feed reader? Grab our feed!

(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.

Read more Similar C Programs
Learn C Programming
Number System

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

To get regular updates on new C programs, you can Follow @c_program

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

our page!

Share this program with your Facebook friends now! by liking it

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

Like to get updates right inside your feed reader? Grab our feed!


List of C Programs
(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 Programs
Learn C Programming

Simple C Programs

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

To get regular updates on new C programs, you can Follow @c_program

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

our page!

Share this program with your Facebook friends now! by liking it

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

Like to get updates right inside your feed reader? Grab our feed!

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