Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Last active December 12, 2020 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkphp/00d32098ff788b3d54ef7cb20bac466e to your computer and use it in GitHub Desktop.
Save thinkphp/00d32098ff788b3d54ef7cb20bac466e to your computer and use it in GitHub Desktop.
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