« Back to profile of iBassim

  • C++

    Prime numbers by using function

    A function determines whether an integer is prime or not.

    15:18 Dec 19 2010 | Tags :
    						#include<iostream>
using namespace std;
int prime(int n) {
    int i=2;
    while(i<n) {
                if(n%i==0) {
                           return 0;
                           }
                       i++;
                       
    }
                       return 1;
    }
    int main() {
        int n;
        
        cin>>n;
        
        if(prime(n)==0) {
                        cout<<n<<" is not a prime number\n";
                        } else {
                               cout<<n<<" is a prime number\n";
                               }
        
        
        return 0;
        }
    			         
Add comment
To add a comment, please : Login or Sign up
    iBassim
    Bassim Mohammed
    • Biography A programmer, a CS student, iPhonian, iPadian, movies &amp; TV shows obsessed, addicted to music. Helpful, optimistic, tweetative, sharp-witted, acute and g

    • View full profile »
  • New visitor?

    On setCode, you can save your codes, functions and classes, you can also share them with your friends, and track your favorite developer

    Join the SetCode community
  • Your language here :