Last active
December 12, 2020 08:11
-
-
Save thinkphp/00d32098ff788b3d54ef7cb20bac466e to your computer and use it in GitHub Desktop.
repeat ... until control flow in c language
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> | |
#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