Skip to main content

Simple Example Program for Function Find Smallest Number In C++

1 min read Updated June 30, 2026
Share:
On this page (8sections)

About this program

This is an example program in c function example programs. Read the concept first: C++ Function Basics, then study the code and output below.

Definition

A function is a group of code or code block, which performs a specific task.

For Better Understanding,

Syntax

return_type function_name(argumnent)
{
 // body Of the Function
}

Simple Example Program Of Function Find Smallest Number

/*  Example Program For Simple Example Program Of Function Find Smallest Number In C++
    little drops @ thiyagaraaj.com
    Coded By:THIYAGARAAJ MP             */

#include<iostream>
#include<conio.h>

using namespace std;

// Find Smallest Number compare Function
int compare(int a, int b) {
    return (a < b) ? a : b;
}

int main() {
    cout << "\nSmallest Number :" << compare(1, 10);
    cout << "\nSmallest Number :" << compare(31, 10);
    cout << "\nSmallest Number :" << compare(11, 8);
    getch();
    return 0;
}

Sample Output

Smallest Number :1
Smallest Number :10
Smallest Number :8

Learn the concept first, then study the code:

Frequently Asked Questions

What does this C++ program do?
It is a C++ example program that demonstrates Simple for Function Find Smallest Number, including the complete source code and the expected sample output.
How do I compile and run this C++ program?
Save the code in a `.cpp` file, compile it with `g++ filename.cpp -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses user-defined functions, illustrating a common pattern in C++ programming.

Related Tutorials

Search tutorials