Skip to content

Instantly share code, notes, and snippets.

@thinkphp

thinkphp/repeatuntil.c

Last active Dec 12, 2020
Embed
What would you like to do?
repeat ... until control flow in c language
#include <stdio.h>
#define __repeat__ do
#define __until__(COND) while(!(COND))
int isPrime(int n) {
if( n == 0 || n == 1 ) return 0;
if( n == 2 || n == 3 ) return 1;
int i = 2,
prime = 1;
while((i*i) <= n && prime) {
prime = ((n % i) != 0);
i++;
}
return prime;
}
int main(int argc, char const *argv[])
{
int num,
i,
j;
num = 1000;
i = 2;
j = 0;
__repeat__ {
if( isPrime( i ) ) {
j++;
printf("%d ", i);
}
i++;
} __until__( j == num );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment