Welcome

Hi! This blog is for beginners of c++ and java .You can check and pick codes for your programming assignments. This will also help you to understand the concepts of these programming languages. Its all about programming.

Checking Prime Number(By Arrays)

Tuesday, June 7, 2011

#include <iostream.h>
void prime(int x[]);
int main()
{
    int a[10];
    for (int b=0;b<10;b++)
    {
        cout <<"Enter the Number " << b << ": ";
        cin>>a[b];
        cout <<"\n\n";
    }
    prime(a);
    return 0;
}
void prime(int x[])
{
    int check=0;
    for (int c=0;c<10;c++)
    {
        check=0;
        for (int a=2;a<x[c];a++)
        {
            if (x[c]%a==0)
            {
                check++;
            }
            else
            {
                check=check;
            }
        }
        if (check>0)
        {
            cout <<"\n\n"<<x[c]<<" is not prime";
        }
        else
        {
            cout <<"\n\n"<<x[c]<<" is prime ";
        }
    }
    return;
}