Knowee
Questions
Features
Study Tools

Write Jumping and Branching Statements, If-Else Statements, Looping Statements in C

Question

Write Jumping and Branching Statements, If-Else Statements, Looping Statements in C

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here are examples of each of those in C:

  1. Jumping and Branching Statements:

    • goto statement:
    #include <stdio.h>
    int main() {
        int num = 1;
        label:
        printf("%d ", num);
        num++;
        if(num <= 10)
            goto label;
        return 0;
    }
    
    • break statement:
    #include <stdio.h>
    int main() {
        for(int i = 0; i < 10; i++) {
            if(i == 5)
                break;
            printf("%d ", i);
        }
        return 0;
    }
    
    • continue statement:
    #include <stdio.h>
    int main() {
        for(int i = 0; i < 10; i++) {
            if(i == 5)
                continue;
            printf("%d ", i);
        }
        return 0;
    }
    
  2. If-Else Statements:

    #include <stdio.h>
    int main() {
        int num = 10;
        if(num > 5)
            printf("Number is greater than 5");
        else
            printf("Number is not greater than 5");
        return 0;
    }
    
  3. Looping Statements:

    • for loop:
    #include <stdio.h>
    int main() {
        for(int i = 0; i < 10; i++)
            printf("%d ", i);
        return 0;
    }
    
    • while loop:
    #include <stdio.h>
    int main() {
        int i = 0;
        while(i < 10) {
            printf("%d ", i);
            i++;
        }
        return 0;
    }
    
    • do-while loop:
    #include <stdio.h>
    int main() {
        int i = 0;
        do {
            printf("%d ", i);
            i++;
        } while(i < 10);
        return 0;
    }
    

This problem has been solved

Similar Questions

Jumping Statements in c

1.4 Jumping and Branching Statements, If-Else Statements, Looping Statements

Which of these loop statements exist in C?

GIVE ME SOME QUTIONS TO PRACTICE LOOPS IN C

What is the syntax of a basic "if" statement in C?

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.