Wednesday, August 21, 2013

Write a c program to generate all prime numbers between 1 to n


/*------------------------------------------------------------------------------------------------
Program    : Write a c program to generate all prime numbers between 1 to n.
Created By: JABIR DAUD PATHAN
Branch       : COMPUTER ENGINEERING
-------------------------------------------------------------------------------------------------*/

//----------------------  Header Files  ----------------------------------
#include<stdio.h>
#include<conio.h>
//----------------------  Main Function  --------------------------------
void main()
 {
  int no,i; 
  clrscr();
  printf("Enter any number or Range==>");
  scanf("%d",&no); 
  for(i=1;i<=no;i++) 
   {
    if(i==1||i==2||i==3||i==5||i==7) 
     {
      printf("\t%d",i);
     }
    else
     if(i%2>0&&i%3>0&&i%5>0&&i%7>0) 
      {
       printf("\t%d",i);
      }
   }
  getch();
 }
//---------------------  End of Main Function  --------------------------










/*-----------------<< OUTPUT SCREEN  >>-------------------*/

Enter any number or Range==>15
            1       2       3       5       7       11      13

No comments:

Post a Comment