PROGRAMMING IN C- A function which outputs all the prime numbers between 2 and a given positive integer n:
Saturday, 31 March 2018
This program will allow users to find the the prime numbers between 2 and a given positive integer
Complied On : Code::Blocks 17.0
Save :- .c file (C Program)
Created By :- Lukas Yooma
Save :- .c file (C Program)
Created By :- Lukas Yooma
Find the code below
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,j, n=0,prime;
printf("PLEASE ENTER THE NUMBER TO FIND ITS PRIME NUMBERS :\t");
scanf("%d", &prime);
for(i = 2; i <=prime; i++)
{
for (j=1; j<= i; j++)
{
if (i%j == 0)
{
n++;
}
}
if (n == 2)
printf("%d\n", i);
n=0;
}
getchar();
main();
}
Thanks for reading, leave a comment for any queries