Friday 3 June 2016

Write a program that inputs a number in main() function and passes it to a function. The function displays whether number is prime or not.

#include<iostream.h>
#include<conio.h>
void prime(int n);
void main()
{
        clrscr();
        int num;
        cout<<"Enter a number: ";
        cin>> num;
        prime(num);
        getch();
}
void prime(int n)
{
        int p =1;
        for(int j=2; j<n; j++)
                if(n%j == 0)
                {
                        p = 0;
                        break;
                }
        if(p == 1)
                cout<<"The number is prime";
        else
                cout<<"The number is not prime";
}
Share:

0 comments:

Post a Comment

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

About Me

My photo
A group of two, with a little hope of helping beginners to learn how to code :)
Powered by Blogger.

Comments

Facebook

Ad Home

Follow Us

Random Posts

Sponsor

Recent Posts

Header Ads

Popular Posts

Copyright © Functions in C++ | Powered by Blogger

Design by ThemePacific | Blogger Theme by NewBloggerThemes.com | Distributed By Blogger Templates20