**Q.**Write a C program to accept a specific last number and print all the less then or equal prime number.

*or*

**Q.**Write a C program to print the prime number between 1 to n number.

for example: 1 to 100

**Ans.**

__Note:-__

1. 1 is not the prime number.

2. All even number is not the prime number except the number 2.

/*C program to print 1 to 100 prime numbers*/

**#include**<

**stdio.h**>

**#include**<

**conio.h**>

int main()

{

int num,n,div,p;

printf("Enter any number: ");

scanf("%d",

**&**num);

for(n=2; n<=num; n++)

{

for(div=2; div<n; div++)

{

if(n%div==0)

{

p=0;

**break**;

}

p=1;

}

if(p)

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

}

getch();

**return 0**;

}

**/************Output************/**

Screen shot for print the prime number between 1 to 100 C program |

Related program:

Can u explain the program with example please.

ReplyDeletethe program has an error

ReplyDeletethe above program for(div=1;div<n;div++)

ReplyDeletethen you get correct output

Thank U Dinesh Bera..,

ReplyDeleteFinding prime numbers in this way helped me a lot in debugging my Assembly Code for finding N prime numbers... :)

Code Dumped :P give correct code

ReplyDeleteThank you

ReplyDeleteI cannot understand the if else condition you used in prime number program

ReplyDeleteFormulate a model for picking out the prime number from this range and describe the input, processing and output intend in an algorithm to display all the prime numbers between 1 and 100?

ReplyDeleteI need urgent answers please.

What about 2 .. it will not print 2 ..??

ReplyDelete