Friday, 18 November 2016

Another method to print prime nos. in a given range

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

void check_prime (int x,int y);
void main()
{ clrscr();
  int x,y,z;
  cout<<"Enter the range below" ;
  cout<<"From ";
  cin>>x;
  cout<<"To ";
  cin>>y;
  check_prime(x,y);
  getch();
}

void check_prime(int x,int y)
{ int a,b,c,d;
  for(int i=x;i<=y;i++)
     { int ret=0;
       for (int j=1;j<=i;j++)
  { c=i%j;
    if (c==0)
{ ret++;
}
  }
       if (ret==2)
 { cout<<i<<" is a prime no. \n";
 }
     }
getch();
}

No comments:

Post a Comment

Basic Implementation of Array as a Pointer

#include<iostream.h> #include<conio.h> void main() { clrscr();   int arr[5];   cout<<"Enter 5 nos. ";   f...