Computer Science, asked by kushagar18, 1 year ago

write a program in c++ to print the prime number between 100-200.

Answers

Answered by prerana57
2

#include <stdio.h>

int main(void) {

unsigned short int prime[201]; // making a sieve array which will be telling which are prime numbers

int i = 0;

fill : // Initializing array with 1. Here 1 is convention used for indicating the prime number; 0 & 1 are excluded in this pretext

prime[i++] = 1;

if(i < 201) { // this routine will work like the for loop

goto fill;

}

i = 2;

int j;

sieve : // Constructing sieve routine

if(prime[i] == 1) { // if the number is prime then make all its multiple non prime

j = i * 2;

checkmultiples :

prime[j] = 0;

j+=i;

if(j <= 200) {

goto checkmultiples;

}

}

i++;

if( i * i <= 200) {

goto sieve;

}

 

int countprimes = 0;

i = 100;

count : //counting prime routine

if(prime[i++]) {

countprimes++;

}

if(i < 201) {

goto count;

}

 

printf("%d\n",countprimes);


kushagar18: Thank mam thanks so much
Similar questions