Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <ctype.h>
- int isPrime(int);
- int main(void)
- {
- char choice;int ch, i, ctr;
- clrscr();
- do
- {
- ctr = 1;
- printf("\nPress 1 to print prime numbers\n");
- printf("Press 2 to print non-prime numbers\n");
- scanf("%d", &ch);
- switch(ch)
- {
- case 1: printf("The prime numbers are\n");
- for(i = 2; i <= 2000; i++)
- {
- if(isPrime(i))
- {
- printf("%d,", i);
- ctr++;
- }
- if((ctr%28) == 0)
- {
- printf("\nPress enter to see the next set of numbers....");
- getch();
- clrscr();
- ctr = 1;
- printf("\n\n");
- }
- }
- break;
- case 2: printf("The non-prime numbers are\n");
- for(i = 2; i <= 2000; i++)
- {
- if(!isPrime(i))
- {
- printf("%d,", i);
- ctr++;
- }
- if((ctr%40) == 0)
- {
- printf("\nPress enter to see the next set of numbers....");
- getch();
- clrscr();
- ctr = 1;
- printf("\n\n");
- }
- }
- break;
- }
- printf("\nDo you want to run again (Y/N)? ");
- choice = getche();
- }
- while(toupper(choice) == 'Y');
- getch();
- return 0;
- }
- int isPrime(int num)
- {
- int limit = num/2;
- int ret = 1, i;
- for(i = 2; i <=limit; i++)
- {
- if((num%i) == 0)
- {
- ret = 0;
- break;
- }
- }
- return ret;
- }
Add Comment
Please, Sign In to add comment