Write a program that print all prime numbers from 1 to n.

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<iostream.h>

void main()
{
    int n,p,k=1;;
    clrscr();
    cout<<"Enter any number, n = ";
    cin>>n;

    for(int i=2;i<=n;i++)
    {
       p=1;
       int t=sqrt(i);

       for(int j=2;j<=t;j++)
          if(i%j==0)
          {
             p=0;
         break;
          }
       if(p==1)
       {
          cout<<"\n"<<k<<" Prime number = "<<i;
          k++;
       }
    }

    getch();
}



///////////////////////////////////////////////////////////////////////////
Copy & paste this code in your TC & run, then you will get output.......
If you have any problem please comment below.........