C++ program to demonstrate the use of goto statement
kw.cpp
#include <iostream>
using namespace std;
int main()
{
    int n;
    cout<<"Enter a number ";
    cin>>n;
    if (n % 2 == 0)
    {
        goto EVEN;
    }
    else
    {
        goto ODD;
    }
EVEN:
    cout<<n<<" is an EVEN number \n";
    return (0);
ODD:
    cout<<n<<" is an ODD number \n";
    return 0;
}
Output
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out Enter a number 3.14 3 is an ODD number kodingwindow@kw:~$ ./a.out Enter a number 99 99 is an ODD number kodingwindow@kw:~$
Advertisement