Horje
no argument but return value in c++ Code Example
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.";
    }
}




Cpp

Related
c++ how to inherit from a template class Code Example c++ how to inherit from a template class Code Example
sort using comparator anonymous function c++ Code Example sort using comparator anonymous function c++ Code Example
what are manipulators in c++ Code Example what are manipulators in c++ Code Example
C++ Detect when user presses arrow key Code Example C++ Detect when user presses arrow key Code Example
product of array in cpp Code Example product of array in cpp Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11