Examples of goto statement in c++ programing
All Contributions
Write a program with goto statement and break statement:
#include<iostream.h>
using namespace std;
int main()
{
int num1,num2,sum;
start:
cout<<"\nEnter two number: ";
cin>>num1>>num2;
if(num1== 0 || num2==0)
break;
sum = num1+num2;
cout<<"Total: "<<sum;
goto start;
cout<<"this is next statement";
return 0 ;
}
Write a Program that find out whether a given number is equal or not:
#include<iostream>
using namespace std;
int main()
{
int num1,num2;
cout<<"Enter Two number: ";
cin>>num1>>num2;
if(num1==num2)
goto transfer;
else
cout<<"Given number are not Equal";
transfer: {
cout<<"\nGiven number are Equal "<<x;
}
return 0;
}
Write a program using goto where we will print numbers from 1 to 10 and the place of 10 numerically we will print it alphabetically :
#include <iostream>
using namespace std;
int main()
{
for (int i = 1; i <= 10; i++)
{
if (i == 10)
{
goto q;
}
cout << i << " "
<< "Element=" << i << endl;
}
q:
cout << "I am the 10th element = ten";
return 0 ;
}
Write a program using goto where we will print numbers from 1 to 10 and the place of 10 numerically we will print it alphabetically :
#include <iostream>
using namespace std;
int main()
{
for (int i = 1; i <= 10; i++)
{
if (i == 10)
{
goto q;
}
cout << i << " "
<< "Element=" << i << endl;
}
q:
cout << "I am the 10th element = ten";
return 0 ;
}
total contributions (6)
Write a program with goto statement and continue :