Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

no argument but return value in c++

#include <iostream>
using namespace std;

void prime(int n);

int main()
{
    int num;
    cout << "Enter a positive integer to check: ";
    cin >> num;
    
    // Argument num is passed to the function prime()
    prime(num);
    return 0;
}

// There is no return value to calling function. Hence, return type of function is void. */
void prime(int n)
{
    int i, flag = 0;
    for (i = 2; i <= n/2; ++i)
    {
        if (n%i == 0)
        {
            flag = 1;
            break;
        }
    }

    if (flag == 1)
    {
        cout << n << " is not a prime number.";
    }
    else {
        cout << n << " is a prime number.";
    }
}
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #argument #return
ADD COMMENT
Topic
Name
9+6 =