C++ For Loop Quiz

C++ For Loop Quiz

University

10 Qs

quiz-placeholder

Similar activities

Java Operators

Java Operators

University

14 Qs

FST Class 2023- Quiz 5

FST Class 2023- Quiz 5

University

9 Qs

C++ Fundamentals

C++ Fundamentals

University

10 Qs

[CONTROL FLOW STATEMENTS]

[CONTROL FLOW STATEMENTS]

University

15 Qs

Control Statements - Java

Control Statements - Java

University

15 Qs

DECISION MAKING IN C

DECISION MAKING IN C

University

10 Qs

Kuizi 14 - Web

Kuizi 14 - Web

10th Grade - University

15 Qs

C++ 2nd Online Quiz

C++ 2nd Online Quiz

University

10 Qs

C++ For Loop Quiz

C++ For Loop Quiz

Assessment

Quiz

Computers

University

Hard

Created by

Harshita Kanojia

FREE Resource

10 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the purpose of a "for loop" in C++?

To execute code only once

To execute code repeatedly based on a condition

To define a function

To declare a variable

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is the correct syntax for a "for loop" in C++?

for (initialization, condition, increment/decrement) { code }

for (initialization; condition; increment/decrement) { code }

for initialization; condition; increment/decrement { code }

for { initialization; condition; increment/decrement }

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the output of the following code? for (int i = 1; i <= 3; i++) { cout << i << " "; }

1 2 3

1 2 3 4

0 1 2

3 2 1

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is a prime number?

A number that is divisible by any number

A number that has only two distinct divisors: 1 and itself

A number that is always even

A number that is always odd

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will the function isPrime(7) return? bool isPrime(int num) { if (num <= 1) return false; for (int i = 2; i <= num / 2; i++) { if (num % i == 0) { return false; } } return true; }

true

false

0

Compilation error

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does the following factorial program do? int factorial = 1; for (int i = 1; i <= 5; i++) { factorial *= i; } cout << factorial;

Calculates the sum of first 5 natural numbers

Calculates 5! (5 factorial)

Prints numbers from 1 to 5

Finds the largest number among 5 numbers

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

How many times will the following loop execute? for (int i = 0; i < 5; i++) { cout << i; }

4 times

5 times

Infinite times

6 times

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?