049. Write a program to accept a number and print prime numbers between 2 and n in C language

 
#include<stdio.h>
#include<conio.h>
#include<process.h>
main()
{
	int i,flag=1,n,newn;
	clrscr();
	printf("Enter number...");
	scanf("%d",&n);
	for(newn=2;newn<=n;newn++)
	{
		flag=1;
		for(i=2;i<=newn/2 ;i++)
		{
			if(newn%i==0)
			{
			flag=0;
			break;
			}
		}
		if(flag==1)
			printf("%d ",newn);
	}
	getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *