C++ program to find Largest of two numbers || comparison of two numbers || Functions || C++
In this, we are going to see Functions, the program is based on function which Calculates, Profit or Loss.

The code given below can be used for TURBO C++ Compiler:-

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

int num1, num2;

void get_data()
{
    cout<<"\nEnter the two numbers to find the largest number from both\n";
    cin>>num1>>num2;
}

void largest_number()
{
    if(num1>num2)
    {
        cout<<"The number "<<num1<<" is largest";
    }
    else
    {
        cout<<"The number "<<num2<<" is largest";
    }
}

void main()
{
    clrscr();
    get_data();
    largest_number();

    getch();
}
	
    
The code given below can be used for g++/gcc Compiler:-

#include<iostream>
using namespace std;

int num1, num2;

void get_data()
{
    cout<<"\nEnter the two numbers to find the largest number from both\n";
    cin>>num1>>num2;
}

void largest_number()
{
    if(num1>num2)
    {
        cout<<"The number "<<num1<<" is largest";
    }
    else
    {
        cout<<"The number "<<num2<<" is largest";
    }
}

int main()
{
    get_data();
    largest_number();

    return 0;
}
	
    
#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post