King Fai Oniversity College of Engineering Exam Engineering

King Fai Oniversity College of Engineering Exam: Engineering Programming CS209, Eal 2014 Student Name: D Student ID Total Marks: 5 1. When we commonly use for loop? A. To execute statements at least once B. To execute statements for an infinite number of times C. To execute statements for a fixed number of times D. None of above 2. How many times the following oode prints the word \"Programming for(i-0; i c 50. i +2) cout

Solution

1. C. To execute statements for a fixed number of times.
Syntax of for loop: for(initialize; condition; increment)
Eg: If you want to print numbers from 1 to 10
for(int i = 1; i <= 10; i++)
{
print i
}
For loop will execute only 10 times in this case.

2. All the mentioned options are wrong.
It will print Programming 25 times.
Value of i would be 0, 2, 4, 6, 8...,50
For each of these values Programming would be printed.
Total number of values is from 0 to 48 ==> 25

3. D There should not be a semicolon after while
Problem with semicolon after while is that it will execute infinite times because value of sum will not increment

 King Fai Oniversity College of Engineering Exam: Engineering Programming CS209, Eal 2014 Student Name: D Student ID Total Marks: 5 1. When we commonly use for

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site