Sunday 8 April 2012

9).Check Whether A Given Number Is Prime Or Not.


#include<conio.h>
#include<iostream.h>
void main()
{
 clrscr();
    int r, N;

   cout<<"Enter the Number" ;
   cin>>N;
   for(int i=2;i<=N-1;i++)
   {
    if(N%i==0)
     r=1;
    break;
   }
   if(r==0)
        cout<<"The Number "<<N<<"is PRIME.";
   else
        cout<<"The Number is NOT PRIME.";

    getch();

}

No comments:

Post a Comment

Write a program which reads a set of integers into an integer array and then prints "YES"if all of them are same otherwise print "NO".

#include<stdio.h> int main() { int a[10],M=0,i,n; printf("enter a value for n\n"); scanf("%d",&n); fo...