How to pause execution for 5 seconds in C

2 Answers

0 votes
#include <unistd.h> // sleep()
#include <stdio.h>

int main() {
    printf("Pausing for 5 seconds...\n");
    
    sleep(5);  // Pause execution for 5 seconds
    
    printf("Resuming execution.\n");
    
    return 0;
}

  
  
/*
run:
  
Pausing for 5 seconds...
Resuming execution.
  
*/

 



answered Apr 29, 2025 by avibootz
0 votes
#include <windows.h>
#include <stdio.h>

int main() {
    printf("Pausing for 5 seconds...\n");
    
    Sleep(5000);  // Pause execution for 5000 milliseconds (5 seconds)
    
    printf("Resuming execution.\n");

    return 0;
}



/*
run

Pausing for 5 seconds...
Resuming execution.

*/

 



answered Apr 29, 2025 by avibootz

Related questions

1 answer 148 views
148 views asked Apr 29, 2025 by avibootz
1 answer 171 views
2 answers 195 views
1 answer 167 views
1 answer 185 views
1 answer 141 views
141 views asked Apr 30, 2025 by avibootz
1 answer 166 views
...