Example program break continue goto statement in C C++

Example programs for break, continue and goto statements in C

Unconditional branching statements के बारे में अधिक जानकारी के लिए देखें— Break, Continue and Goto in C

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

break statement example program in C

#include<stdio.h>
int main()
{
    int n=1;
    while (n<=3)
    {
        printf("ABC\n");
        n++;
        break;
        printf("DEF\n");
    }
    return 0;
}

Output:

ABC

continue statement example program in C

#include<stdio.h>
int main()
{
    int n=1;
    while (n<=3)
    {
        printf("ABC\n");
        n++;
        continue;
        printf("DEF\n");
    }
    return 0;
}

Output:

ABC
ABC
ABC

goto statement example program in C

#include<stdio.h>
int main()
{
    int n=1;
    printf("ABC\n");
    goto xyz;
    printf("DEF\n");
    xyz:
    return 0;
}

Output:

ABC

Example programs for break, continue and goto statements in C++

break statement example program in C++

#include<iostream>
using namespace std;
int main()
{
    int n=1;
    while (n<=3)
    {
        cout<<"ABC\n";
        n++;
        break;
        cout<<"DEF\n";
    }
    return 0;
}

Output:

ABC

continue statement example program in C++

#include<iostream>
using namespace std;
int main()
{
    int n=1;
    while (n<=3)
    {
        cout<<"ABC\n";
        n++;
        continue;
        cout<<"DEF\n";
    }
    return 0;
}

Output:

ABC
ABC
ABC

goto statement example program in C++

#include<iostream>
using namespace std;
int main()
{
    int n=1;
    cout<<"ABC\n";
    goto xyz;
    cout<<"DEF\n";
    xyz:
    return 0;
}

Output:

ABC

Similar programs in C and C++

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Greater in two numbers (if else)
  5. Finding grade from percent (else if ladder)
  6. Total percent and division (else if ladder)
  7. Greatest in three numbers (nested if)
  8. Simple calculator program (switch case single case)
  9. Switch between Mon to Sun (switch case single case)
  10. Checking vowel or consonant (switch case multiple case)
  11. Number of days in a month (switch case multiple case)
Share it to:

C C++ program to find total percent and division

C C++ program to find total percent and division

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

Unconditional branching statements के बारे में अधिक जानकारी के लिए देखें— Break, Continue and Goto in C

Flowchart to find total percent and division

Flowchart to find total percent and division of five subjects

C program to find total percent and division

#include<stdio.h>
int main()
{
    int s1,s2,s3,s4,s5,t;
    float p;
    printf("Enter marks of five subjects:\n");
    scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);
    t=s1+s2+s3+s4+s5;
    p=t/5.0;
    printf("Total    = %d\n",t);
    printf("Percent  = %f\n",p);
    if(p>=60)
        printf("Division = First");
    else if(p>=45)
        printf("Division = Second");
    else if(p>=33)
        printf("Division = Third");
    else
        printf("Division = Fail");
    return 0;
}

C++ program to find total percent and division

#include<iostream>
using namespace std;
int main()
{
    int s1,s2,s3,s4,s5,t;
    float p;
    cout<<"Enter marks of five subjects: "<<endl;
    cin>>s1>>s2>>s3>>s4>>s5;
    t=s1+s2+s3+s4+s5;
    p=t/5.0;
    cout<<"Total    = "<<t<<endl;
    cout<<"Percent  = "<<p<<endl;
        if(p>=60)
        cout<<"Division = First";
    else if(p>=45)
        cout<<"Division = Second";
    else if(p>=33)
        cout<<"Division = Third";
    else
        cout<<"Division = Fail";
    return 0;
}

Output of C C++ program to find total percent and division

Enter marks of five subjects:
40 50 60 70 81
Total     =  301
Percent   =  60.200001
Division  =  First
Enter marks of five subjects:
4 5 6 7 8
Total     =  30
Percent   =  6.000000
Division  =  Fail

List of all control statement programs in C C++

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Greater in two numbers (if else)
  5. Finding grade from percent (else if ladder)
  6. Greatest in three numbers (nested if)
  7. Simple calculator program (switch case single case)
  8. Switch between Mon to Sun (switch case single case)
  9. Checking vowel or consonant (switch case multiple case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Write a C C++ program to find number of days in a month

Write a C C++ program to find number of days in a month

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

Switch statement और multibranching statements के बारे में अधिक जानने के लिए देखें—Switch statements in C

Flowchart to find number of days in a month

Flowchart to find number of days in months

C program to find number of days in a month

#include<stdio.h>
int main()
{
    int month;
    printf("Enter month number: ");
    scanf("%d",&month);
    switch(month)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
        printf("31 days");
        break;
        case 4:
        case 6:
        case 9:
        case 11:
        printf("30 days");
        break;
        case 2:
        printf("28 days");
        break;
        default:
        printf("Invalid month number");
    }
    return 0;
}

C++ program to find number of days in a month

#include<iostream>
using namespace std;
int main()
{
    int month;
    cout<<"Enter month number: ";
    cin>>month;
    switch(month)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
        cout<<"31 days";
        break;
        case 4:
        case 6:
        case 9:
        case 11:
        cout<<"30 days";
        break;
        case 2:
        cout<<"28 days";
        break;
        default:
        cout<<"Invalid month number";
    }
    return 0;
}

Output of C C++ program to find number of days in a month

Enter month number: 1
31 days
Enter month number: 6
30 days
Enter month number: 15
Invalid month number

Related programs in C and C++

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Greater in two numbers (if else)
  5. Finding grade from percent (else if ladder)
  6. Total percent and division (else if ladder)
  7. Greatest in three numbers (nested if)
  8. Simple calculator program (switch case single case)
  9. Switch between Mon to Sun (switch case single case)
  10. Checking vowel or consonant (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Write a C C++ program to check vowel or consonant

Write a C C++ program to check vowel or consonant

Switch statement और multibranching statements के बारे में अधिक जानने के लिए देखें—Switch statements in C

C Language में उपलब्ध Operators और इनके विभिन्न प्रकारो को जानने के लिए देखें—Operators in C

Flowchart to check vowel or consonant

Find Vowel or Consonant flowchart

C program to check vowel or consonant

#include<stdio.h>
int main()
{
    char letter;
    printf("Enter a letter: ");
    scanf("%c",&letter);
    switch(letter)
    {
        case 'a':
        case 'A':
        case 'e':
        case 'E':
        case 'i':
        case 'I':
        case 'o':
        case 'O':
        case 'u':
        case 'U':
        printf("Vowel");
        break;
        default:
        printf("Consonant");
    }
    return 0;
}

C++ program to check vowel or consonant

#include<iostream>
using namespace std;
int main()
{
    char letter;
    cout<<"Enter a letter: ";
    cin>>letter;
    switch(letter)
    {
        case 'a':
        case 'A':
        case 'e':
        case 'E':
        case 'i':
        case 'I':
        case 'o':
        case 'O':
        case 'u':
        case 'U':
        cout<<"Vowel";
        break;
        default:
        cout<<"Consonant";
    }
    return 0;
}

Output of C C++ program to check vowel or consonant

Enter a letter: A
Vowel
Enter a letter: Z
Consonant

Other branching statement programs in C C++

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Greater in two numbers (if else)
  5. Finding grade from percent (else if ladder)
  6. Total percent and division (else if ladder)
  7. Greatest in three numbers (nested if)
  8. Simple calculator program (switch case single case)
  9. Switch between Mon to Sun (switch case single case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Write a C C++ program to switch between Monday to Sunday

Write a C C++ program to switch between Monday to Sunday

Unconditional branching statements के बारे में अधिक जानकारी के लिए देखें— Break, Continue and Goto in C

Switch statement और multibranching statements के बारे में अधिक जानने के लिए देखें—Switch statements in C

Flowchart to switch between Monday to Sunday

Switch between Monday to Sunday flowchart

C program to switch between Monday to Sunday

#include<stdio.h>
int main()
{
    int day;
    printf("Enter day number: ");
    scanf("%d",&day);
    switch(day)
    {
        case 1:
        printf("Mon");
        break;
        case 2:
        printf("Tue");
        break;
        case 3:
        printf("Wed");
        break;
        case 4:
        printf("Thu");
        break;
        case 5:
        printf("Fri");
        break;
        case 6:
        printf("Sat");
        break;
        case 7:
        printf("Sun");
        break;
        default:
        printf("Invalid day number");
    }
    return 0;
}

C++ program to switch between Monday to Sunday

#include<iostream>
using namespace std;
int main()
{
    int day;
    cout<<"Enter day number: ";
    cin>>day;
    switch(day)
    {
        case 1:
        cout<<"Mon";
        break;
        case 2:
        cout<<"Tue";
        break;
        case 3:
        cout<<"Wed";
        break;
        case 4:
        cout<<"Thu";
        break;
        case 5:
        cout<<"Fri";
        break;
        case 6:
        cout<<"Sat";
        break;
        case 7:
        cout<<"Sun";
        break;
        default:
        cout<<"Invalid day number";
    }
    return 0;
}

Output of C C++ program to switch between Monday to Sunday

Enter day number: 1
Mon
Enter day number: 4
Thu
Enter day number: 7
Sun
Enter day number: 9
Invalid day number

Other related program of C and C++ on switch case

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Greater in two numbers (if else)
  5. Finding grade from percent (else if ladder)
  6. Total percent and division (else if ladder)
  7. Greatest in three numbers (nested if)
  8. Simple calculator program (switch case single case)
  9. Checking vowel or consonant (switch case multiple case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Write a simple calculator program in C C++ using switch case

Write a simple calculator program in C C++ using switch case

Switch statement और multibranching statements के बारे में अधिक जानने के लिए देखें—Switch statements in C

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

Flowchart of simple calculator program using switch case

Simple calculator flowchart

Simple calculator program in C using switch case

#include<stdio.h>
int main()
{
    char choice;
    int n1,n2,res;
    printf("Enter choice: ");
    scanf("%c",&choice);
    printf("Enter two numbers: ");
    scanf("%d%d",&n1,&n2);
    switch(choice)
    {
        case '+':
        res=n1+n2;
        break;
        case '-':
        res=n1-n2;
        break;
        case '*':
        res=n1*n2;
        break;
        case '/':
        res=n1/n2;
        break;
        case '%':
        res=n1%n2;
        break;
        default:
        printf("Invalid choice");
    }
    printf("Result = %d",res);
    return 0;
}

Simple calculator program in C++ using switch case

#include<iostream>
using namespace std;
int main()
{
    char choice;
    int n1,n2,res;
    cout<<"Enter choice: ";
    cin>>choice;
    cout<<"Enter two numbers: ";
    cin>>n1>>n2;
    switch(choice)
    {
        case '+':
        res=n1+n2;
        break;
        case '-':
        res=n1-n2;
        break;
        case '*':
        res=n1*n2;
        break;
        case '/':
        res=n1/n2;
        break;
        case '%':
        res=n1%n2;
        break;
        default:
        cout<<"Invalid choice";
    }
    cout<<"Result = "<<res;
    return 0;
}

Output of simple calculator program in C C++ using switch case

Enter choice: +
Enter two numbers: 4 6
Result = 10
Enter choice: %
Enter two numbers: 10 6
Result = 4
Enter choice: #
Enter two numbers: 2 3
Invalid choice
Result = -53446 

Other switch case programs and branching programs in C C++

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Greater in two numbers (if else)
  5. Finding grade from percent (else if ladder)
  6. Total percent and division (else if ladder)
  7. Greatest in three numbers (nested if)
  8. Switch between Mon to Sun (switch case single case)
  9. Checking vowel or consonant (switch case multiple case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Write a C C++ program to find greatest in three numbers

Write a C C++ program to find greatest in three numbers

C के विभिन्न control statements को जानने के लिए देखें— Control statements in C

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

Flowchart to find greatest in three numbers

Finding greatest in three numbers flowchart

C program to find greatest in three numbers

#include<stdio.h>
int main()
{
    int n1,n2,n3;
    printf("Enter three numbers: ");
    scanf("%d%d%d",&n1,&n2,&n3);
    if(n1>n2)
    {
        if(n1>n3)
            printf("Greatest number = %d",n1);
        else
            printf("Greatest number = %d",n3);
    }
    else
    {
        if(n2>n3)
            printf("Greatest number = %d",n2);
        else
            printf("Greatest number = %d",n3);
    }
    return 0;
}

C++ program to find greatest in three numbers

#include<iostream>
using namespace std;
int main()
{
    int n1,n2,n3;
    cout<<"Enter three numbers: ";
    cin>>n1>>n2>>n3;
    if(n1>n2)
    {
        if(n1>n3)
            cout<<"Greatest number = "<<n1;
        else
            cout<<"Greatest number = "<<n3;
    }
    else
    {
        if(n2>n3)
            cout<<"Greatest number = "<<n2;
        else
            cout<<"Greatest number = "<<n3;
    }
    return 0;
}

Output of C C++ program to find greatest in three numbers

Enter three numbers: 4 8 5
Greatest number = 8
Enter three numbers: 33 12 15
Greatest number = 33
Enter three numbers: 40 40 40
Greatest number = 40

List of programs based on if statement and other control statements

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Greater in two numbers (if else)
  5. Finding grade from percent (else if ladder)
  6. Total percent and division (else if ladder)
  7. Simple calculator program (switch case single case)
  8. Switch between Mon to Sun (switch case single case)
  9. Checking vowel or consonant (switch case multiple case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Write a C C++ program to find grade from given percent

Write a C C++ program to find grade from given percent

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

Flowchart to find grade from given percent

Finding grade from given percent flowchart

C program to find grade from given percent

#include<stdio.h>
int main()
{
    float p;
    printf("Enter percent: ");
    scanf("%f",&p);
    if(p>=90)
    {
        printf("A+");
    }
    else if(p>=80)
    {
        printf("A");
    }
    else if(p>=60)
    {
        printf("B");
    }
    else if(p>=40)
    {
        printf("C");
    }
    else
    {
        printf("D");
    }
    return 0;
}

C++ program to find grade from given percent

#include<iostream>
using namespace std;
int main()
{
    float p;
    cout<<"Enter percent: ";
    cin>>p;
    if(p>=90)
    {
        cout<<"A+";
    }
    else if(p>=80)
    {
        cout<<"A";
    }
    else if(p>=60)
    {
        cout<<"B";
    }
    else if(p>=40)
    {
        cout<<"C";
    }
    else
    {
        cout<<"D";
    }
    return 0;
}

Output of C C++ program to find grade from given percent

Enter percent: 95
A+
Enter percent: 88
A
Enter percent: 62
B
Enter percent: 40
C
Enter percent: 25
D

Other if statement programs in C C++

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Greater in two numbers (if else)
  5. Total percent and division (else if ladder)
  6. Greatest in three numbers (nested if)
  7. Simple calculator program (switch case single case)
  8. Switch between Mon to Sun (switch case single case)
  9. Checking vowel or consonant (switch case multiple case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Write a C C++ program to check odd or even number

Write a C C++ program to check odd or even number

C-Language के विभिन्न Control Statements या Programming Constructs को जानने के लिए देखें—Control statements in C

If statement और इसके विभिन्न प्रकारो को जानने के लिए देखें—If statements in C

Flowchart to check odd or even number

Checking whether given number is even or odd flowchart

C program to check odd or even number

#include<stdio.h>
int main()
{
    int n;
    printf("Enter a number: ");
    scanf("%d",&n);
    if(n%2==0)
    {
        printf("Even number");
    }
    else
    {
        printf("Odd number");
    }
    return 0;
}

C++ program to check odd or even number

#include<iostream>
using namespace std;
int main()
{
    int n;
    cout<<"Enter a number: ";
    cin>>n;
    if(n%2==0)
    {
        cout<<"Even number";
    }
    else
    {
        cout<<"Odd number";
    }
    return 0;
}

Output of C C++ program to check odd or even number

Enter a number: 5
Odd number
Enter a number: 72
Even number

Other decision making programs in C C++

  1. Absolute value of number (simple if)
  2. Checking leap year (if else)
  3. Greater in two numbers (if else)
  4. Finding grade from percent (else if ladder)
  5. Total percent and division (else if ladder)
  6. Greatest in three numbers (nested if)
  7. Simple calculator program (switch case single case)
  8. Switch between Mon to Sun (switch case single case)
  9. Checking vowel or consonant (switch case multiple case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Write a C C++ program to find greater in two numbers

Write a C C++ program to find greater in two numbers

C के विभिन्न control statements को जानने के लिए देखें— Control statements in C

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

Flowchart to find greater in two numbers

Greater in two numbers flowchart

C program to find greater in two numbers

#include<stdio.h>
int main()
{
    int n1,n2;
    printf("Enter two numbers : ");
    scanf("%d%d",&n1,&n2);
    if(n1>n2)
    {
        printf("Greater number = %d",n1);
    }
    else
    {
        printf("Greater number = %d",n2);
    }
    return 0;
}

C++ program to find greater in two numbers

#include<iostream>
using namespace std;
int main()
{
    int n1,n2;
    cout<<"Enter two numbers : ";
    cin>>n1>>n2;
    if(n1>n2)
    {
        cout<<"Greater number = "<<n1;
    }
    else
    {
        cout<<"Greater number = "<<n2;
    }
    return 0;
}

Output of C C++ program to find greater in two numbers

Enter two numbers : 30 90
Greater number = 90
Enter two numbers : 45 22
Greater number = 45
Enter two numbers : 50 50
Greater number = 50

List of related selection logic programs

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Finding grade from percent (else if ladder)
  5. Total percent and division (else if ladder)
  6. Greatest in three numbers (nested if)
  7. Simple calculator program (switch case single case)
  8. Switch between Mon to Sun (switch case single case)
  9. Checking vowel or consonant (switch case multiple case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to: