Loop break - Devbhoomi

FREE JOB ALERT & ONLINE TUTORIALS

Hot

Post Top Ad

Monday 6 November 2017

Loop break

#include<stdlib.h>
#include<time.h>
#include<stdio.h>

int main()
{
    int a, b;

    srand(time(NULL));

    while (1)
    {
        // not exactly uniformly distributed, but doesn't matter
        a = rand() % 20;
        printf("%d\n", a);
        if (a == 10)
        {
            break;
        }
        // not exactly uniformly distributed, but doesn't matter
        b = rand() % 20;
        printf("%d\n", b);
    }
    return 0;
}
OUTPUT
3
14
10

No comments:

Post a Comment

Post Top Ad