No arguments passed and no return value In C++


SUBMITTED BY: suru4dan

DATE: May 23, 2017, 9:13 a.m.

FORMAT: C++

SIZE: 645 Bytes

HITS: 440

  1. # include <iostream>
  2. using namespace std;
  3. void prime();
  4. int main()
  5. {
  6. // No argument is passed to prime()
  7. prime();
  8. return 0;
  9. }
  10. // Return type of function is void because value is not returned.
  11. void prime()
  12. {
  13. int num, i, flag = 0;
  14. printf("Enter a positive integer enter to check: ");
  15. cin >> num;
  16. for(i = 2; i <= num/2; ++i)
  17. {
  18. if(num % i == 0)
  19. {
  20. flag = 1;
  21. break;
  22. }
  23. }
  24. if (flag == 1)
  25. {
  26. cout << num << " is not a prime number.";
  27. }
  28. else
  29. {
  30. cout << num << " is a prime number.";
  31. }
  32. }

comments powered by Disqus