# Program to print prime numbers between 1 to n

#include <stdio.h>

int main()

{

int i, j, n, isPrime; //isPrime is used as flag variable

/* Reads upper limit to print prime */ printf(“Find prime numbers between 1 to : “); scanf(“%d”, &n);

printf(“\nAll prime numbers between 1 to %d are:\n”, n);

/* Finds all Prime numbers between 1 to n */ for(i=2; i<=n; i++)

{

/* Assume that the current number is Prime */ isPrime = 1;

/* Check if the current number i is prime or not */ for(j=2; j<=i/2; j++)

{

/*

* If i is divisible by any number other than 1 and self

* then it is not prime number

*/ if(i%j==0)

{

isPrime = 0; break;

}

}

/* If the number is prime then print */ if(isPrime==1)

{

printf(“%d is Prime number\n”, i);

}

}

return 0;

}

**Output:-**

`Find prime numbers between 1 to : 100`

All prime numbers between 1 to 100 are:

2 is Prime number

3 is Prime number

5 is Prime number

7 is Prime number

11 is Prime number

13 is Prime number

17 is Prime number

19 is Prime number

23 is Prime number

29 is Prime number

31 is Prime number

37 is Prime number

41 is Prime number

43 is Prime number

47 is Prime number

53 is Prime number

59 is Prime number

61 is Prime number

67 is Prime number

71 is Prime number

73 is Prime number

79 is Prime number

83 is Prime number

89 is Prime number

97 is Prime number