Advance Programs On For LoopLearn C ProgrammingLearn ProgrammingLoop Control StructuresResources

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

By September 18, 2012 February 5th, 2018 No Comments

#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

DEMO01