Sunday, February 8, 2015

Prime Number Check- Learn

The given number is a prime number or composite number

#include<iostream.h>
#include<conio.h>
main()
{
            int n,found=0;
            cout<<”Enter the number”’;
            cin>>n;
            for(int i=2;i<=n/2+1;i++)
            {
                        If(n%i==0)
                        {
                                    found=1;
                                    break;
}
}
If(found==1)
cout<<”The given number is a composite number”;
else
            cout<<”the given number is a prime number”;

getch();
}

Share

& Comment

0 comments:

Post a Comment

 

Copyright © 2015 Code Fervor™ is a registered trademark.

Designed by Templateism By Naman Kumar