Created
April 4, 2017 14:41
-
-
Save paulohrpinheiro/34c3dfef06c4f67725498c7693df5cf8 to your computer and use it in GitHub Desktop.
Quantos números aleatórios gero em 1 segundo? - C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> // printf | |
#include <unistd.h> // alarm | |
#include <signal.h> // signal | |
#include <stdlib.h> // exit | |
#include <stdbool.h> // true | |
int64_t how_many; | |
void handler(int signal) { | |
if (signal==SIGALRM) { | |
printf("%ld\n", how_many); | |
exit(EXIT_SUCCESS); | |
} | |
} | |
void main(void) { | |
alarm(1); | |
signal(SIGALRM, handler); | |
how_many = 0; | |
while(true) { | |
random()%100; | |
how_many++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment