Wap in C to print prime numbers between 1 to N.

Write a C program to print all prime numbers between 1 to N using for loop.
or,

Wap in C to print prime numbers between 1 to N.

:-Prime number

A Prime number is a natural number greater than 1 that is only divisible by either 1 or itself. All numbers other than prime numbers are
known as composite numbers. There are infinitely many prime numbers, here is the list of first few prime numbers
2 3 5 7 11 13 17 19 23 29 31 37...

#include<stdio.h>
#include<conio.h>
int main()
{
int num, i, j, isprime, n;
printf("To print all prime numbers between 1 to num\n");
printf("Enter the value of num\n");

scanf("%d",&num);

/* For every number between 2 to num, check
whether it is prime number or not */

printf("Prime numbers between %d to %d\n", 1, num);
for(i = 2; i <= num; i++)

{
isprime = 0;


/* Check whether i is prime or not */


for(j = 2; j <= i/2; j++)

{


/* Check If any number between 2 to i/2 divides I
completely If yes the i cannot be prime number */


if(i % j == 0)
{
isprime = 1;
break;

}
}
if(isprime==0 && num!= 1)

printf("%d ",i);
}
getch();
return 0;
}


Output
To print all prime numbers between 1 to num
Enter the value of num
50
Prime numbers between 1 to 50
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47



you can read this article or like my you tube channel
link- https://www.youtube.com/channel/UCRFNMesKeU4caC8SkARK3AQ


for more updates please visit now to our channel


you can read this article or like my page on facebook 


link-

https://mobile.facebook.com/GK-TRICKSconcepts-for-all-competetive-exam-750562121700138/?view_public_for=750562121700138&_rdr


thanks 
(if any complaint about this topic must tell on comment box)




regards



prarocks

No comments:

Post a Comment

Thanks for giving a valuable feedback.

have a great day.

from-prarocks