0% found this document useful (0 votes)
7 views1 page

Exercises On Loops

The document contains exercises focused on loops and programming tasks. It includes writing programs to categorize a person's weight based on height, determining output based on conditional statements, calculating the factorial of a positive integer, and converting an octal number to its decimal equivalent. Each exercise provides specific requirements and examples for implementation.

Uploaded by

gm.manase21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Exercises On Loops

The document contains exercises focused on loops and programming tasks. It includes writing programs to categorize a person's weight based on height, determining output based on conditional statements, calculating the factorial of a positive integer, and converting an octal number to its decimal equivalent. Each exercise provides specific requirements and examples for implementation.

Uploaded by

gm.manase21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Exercises on Loops

1. Write a program which inputs a person’s height (in centimeters) and weight (in
kilograms) and outputs one of the messages: underweight, normal, or
overweight, using the criteria:

Underweight: weight < height/2.5


Normal: height/2.5 <= weight <= height/2.3
Overweight: height/2.3 < weight

2. Assuming that n is 20, what will the following code fragment output when
executed?

if (n >= 0)
if (n < 10)
cout << "n is small\n";
else
cout << "n is negative\n";

3. Write a program which inputs an integer value, checks that it is positive, and
outputs its factorial, using the formulas:

factorial(0) = 1
factorial(n) = n × factorial(n-1)

4. Write a program which inputs an octal number and outputs its decimal
equivalent.
The following example illustrates the expected behavior of the program:

Input an octal number: 214


Octal(214) = Decimal(532)

You might also like