## Description

## Problem 1:

In this problem, we are interested in finding the Body Mass Index (BMI) that

be computed based on the height h in cm and the weight w in kg as follows:

BMI =

w(kg)

h(cm) · h(cm)

· 10000 (1)

## Write a C program that:

1. Scans from the user one real number (float) indicating the weight w in

kg and one integer indicating the height h in cm.

2. Checks if w and h are positive and display an error message and exit

in case any of the numbers is zero or negative as shown in the sample

input/output 1 and 2 below.

3. Compute the BMI and display a message indicating if the person is ”underweight” (i.e.: BMI< 18.5), ”normal weight” (i.e.: 18.5 ≤BMI≤ 24.9)

or ”overweight” (BMI> 24.9) as shown in the sample input/output 3 and

4 below.

Sample input/output 1:

Enter the weight in kg:

10

Enter the height in cm:

-5

Error: The weight and height should not be negative or equal to 0.

Sample input/output 2:

Enter the weight in kg:

0

Enter the height in cm:

1

165

Error: The weight and height should not be negative or equal to 0.

Sample input/output 3:

Enter the weight in kg:

65.5

Enter the height in cm:

157

BMI= 26.6 ==> Overweight

Sample input/output 4:

Enter the weight in kg:

50

Enter the height in cm:

170

BMI=17.3 ==> Underweight

• Submit your solution in a file called ”Problem1.c”.

## Problem 2:

Write a C program that takes 6 integers from the command line and computes

the following:

1. The average of the even integers greater than 10

2. The average of the odd integers greater than 10

3. The average of all the integers greater than 10

Your program should display an ”ERROR!” if the user enters less than 6

integers.

Sample input/output 1:

12 3 60 13 21 33

The number of the odd integers >= 10 is : 3

The average of the odd integers >= 10 is : 22.33

The number of the even integers >= 10 is : 2

The average of the even integers >= 10 is : 36.00

The average of all the integers is : 35.50

2

Sample input/output 2:

22

ERROR!!

• Submit your solution in a file called ”Problem2.c”.

## Problem 3:

Write a C program that scans an integer x from the user and implements a

function void Modify(int *) that modifies the input integer x by replacing its

value by its cube. Your function should change the value of x in the main.

Sample input/output:

Please enter an integer x: 2

Before ==> x =2

After ==> x=8

• Submit your solution in a file called ”Problem3.c”.

## Problem 4:

In this problem, we are interested in finding right triangles. In general, a

triangle is a right triangle if the square of the hypotenuse c is equal to the

sum of the squares of the other two sides a and b, i.e. c

2 = a

2 + b

2

. Write

a program that displays all the right triangles having the sides a, b and c

ranging between 1 and 30.

Sample input/output:

(3, 4, 5)

(5, 12, 13)

(6, 8, 10)

(7, 24, 25)

(8, 15, 17)

(9, 12, 15)

(10, 24, 26)

(12, 16, 20)

(15, 20, 25)

(20, 21, 29)

• Submit your solution in a file called ”Problem4.c”.

3

## Problem 5:

Write a C program that prompts the user to enter N integers and checks

whether there exist four consecutive integers multiple of 5. Accordingly, your

program should:

• Prompt the user to enter N the number of integers in the list (greater

than four and less than 20)

• Prompt the user to enter the N integers and check if there exist four

consecutive integers multiple of 5.

• After the user enters the N integers, your program should display a

message indicating whether there exist four consecutive integers multiple

of 5 as shown below.

In this problem, you are required to submit two solutions (1) without using

arrays and (2) with arrays Hint: For (1), you need to keep record of the last

four integers entered by the user. Accordingly, you need to track the number

entered at iteration i, the previous numbers entered i − 1, i − 2 and i − 3.

Note: If you need to use variables of type ”bool”, you need to add ” #include <stdbool.h>”.

Sample input/output 1:

Please enter N the number of integers in the list:

7

Please enter the 7 integers:

1 5 15 25 30 23 6

Four consecutive integers multiple of 5? YES

Sample input/output 2:

Please enter N the number of integers in the list:

6

Please enter the 6 integers:

2 5 10 15 88 5

Four consecutive integers multiple of 5? NO

• Submit your solutions in two files called ”Problem5withArray.c” and ”Problem5withoutArray.c”.

4