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:
-
Jumping and Branching Statements:
gotostatement:
#include <stdio.h> int main() { int num = 1; label: printf("%d ", num); num++; if(num <= 10) goto label; return 0; }breakstatement:
#include <stdio.h> int main() { for(int i = 0; i < 10; i++) { if(i == 5) break; printf("%d ", i); } return 0; }continuestatement:
#include <stdio.h> int main() { for(int i = 0; i < 10; i++) { if(i == 5) continue; printf("%d ", i); } return 0; } -
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; } -
Looping Statements:
forloop:
#include <stdio.h> int main() { for(int i = 0; i < 10; i++) printf("%d ", i); return 0; }whileloop:
#include <stdio.h> int main() { int i = 0; while(i < 10) { printf("%d ", i); i++; } return 0; }do-whileloop:
#include <stdio.h> int main() { int i = 0; do { printf("%d ", i); i++; } while(i < 10); return 0; }
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.