Basic C Programming - Control Flow

Basic C Programming - Control Flow

12th Grade

10 Qs

quiz-placeholder

Similar activities

Business organizations

Business organizations

9th - 12th Grade

10 Qs

Grammar Review: Unit 1 - 4

Grammar Review: Unit 1 - 4

8th Grade - Professional Development

13 Qs

Zoom Expectations

Zoom Expectations

KG - 12th Grade

7 Qs

In-Person Review

In-Person Review

9th - 12th Grade

12 Qs

Captain Nobody (Ch7-8)

Captain Nobody (Ch7-8)

9th - 12th Grade

10 Qs

Net Plus Day 4

Net Plus Day 4

12th Grade

10 Qs

Câu hỏi ôn tập Python lần 1

Câu hỏi ôn tập Python lần 1

KG - 12th Grade

14 Qs

The Ultimate Movies & Video Games quiz!

The Ultimate Movies & Video Games quiz!

KG - Professional Development

13 Qs

Basic C Programming - Control Flow

Basic C Programming - Control Flow

Assessment

Quiz

Education

12th Grade

Medium

Created by

Hafizul Hasmie

Used 3+ times

FREE Resource

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the syntax for an if statement in C?

if (condition) then // code block

if (condition) { // code block

if (condition) { // code block }

if (condition) then { // code block }

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How do you write an if else statement in C?

if (condition) { // code to be executed if the condition is true } else { // code to be executed if the condition is false }

if (condition) { // code to be executed if the condition is true } else { // code to be executed if the condition is false }

if (condition) { // code to be executed if the condition is true }

if (condition) { // code to be executed if the condition is false } else { // code to be executed if the condition is true }

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Explain the concept of nested if else in C with an example.

In nested if else, the else block must always come before the if block

Example: #include int main() { int num = 10; if(num > 0) { if(num % 2 == 0) { printf("%d is a positive even number.", num); } else { printf("%d is a positive odd number.", num); } } else { printf("%d is not a positive number.", num); } return 0; }

Nested if else can only be used with integers in C

Nested if else is not supported in C

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

When would you use a switch statement in C?

When you have multiple conditions to evaluate and different actions to take based on each condition.

When you want to execute a single action based on a condition

When you need to loop through a collection of elements

When you want to handle exceptions in your code

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the purpose of the default case in a switch statement?

To handle situations where none of the specified cases match the input value.

To provide an alternative case for the input value

To terminate the switch statement immediately

To skip the switch statement and move to the next block of code

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Write a C program to check if a number is positive, negative, or zero using if else.

Here is a sample C program: #include int main() { int num; printf("Enter a number: "); scanf("%d", &num); if(num > 0) printf("%d is positive.", num); else if(num < 0) printf("%d is negative.", num); else printf("%d is zero.", num); return 0; }

printf("%d is non-negative.", num);

if(num >= 0)

int num = 0;

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How can you use nested if else to determine the largest of three numbers in C?

if (num1 >= num2) { if (num1 >= num3) { largest = num1; } else { largest = num3; } } else { if (num2 >= num3) { largest = num2; } else { largest = num3; } }

if (num1 >= num2) { largest = num1; } else { largest = num2; }

if (num1 >= num2 && num1 >= num3) { largest = num1; }

if (num1 >= num2) { largest = num1; } else if (num2 >= num3) { largest = num2; } else { largest = num3; }

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?