Share
Explore BrainMass

# Introduction to C - Conditionals and Basic Functions

1. Given the variables isFullTimeStudent and age , write an expression that evaluates to true if age is less than 19 or isFullTimeStudent is true.

2.Write an expression that evaluates to true if and only if value of the integer variable isAMember is false.

3. Write a conditional that assigns true ( 1 ) to the variable fever if the variable temperature is greater than 98.6 .

4. Write the definition of a function printGrade , which has a char parameter and returns nothing. The function prints on a line by itself the message string Grade: followed by the char parameter (printed as a character) to standard output. Don't forget to put a new line character at the end of your line.

Thus, if the value of the parameter is 'A', the function prints out Grade: A

5. Write a statement that declares a prototype for a function add , which has two int parameters and returns an int .

6. Write the definition of a function max that has three int parameters and returns the largest.

#### Solution Preview

<Ol>
<Li><B>Given the variables isFullTimeStudent and age , write an expression that evaluates to true if age is less than 19 or isFullTimeStudent is true.</B>

Here, there are two conditions, and if either one is true, the expression should have value true. That is, the <I>||</I> (or) operator is to be used:

<I>
age < 19 || isFullTimeStudent == 1
</I>

<Li><B>Write an expression that evaluates to true if and only if value of the integer variable isAMember is false.</B>

Here, if <I>isAMember</I> is false, the expression should be true, and if <I>isAMember</I> is false, the expression should be true. In other words, the expression's value should be the complement/negation of the truth value of <I>isAMember</I>, which means the <I>!</I> (not) operator should be used:

<I>
!isAMember
</I>

Another way of doing the same is:
<I>
isAMember == 0
</I>
(this directly checks whether isAMember is false)

<Li><B>Write a conditional that assigns true ( 1 ) to the ...

#### Solution Summary

Six elementary C programming problems are solved related to conditional expressions and basic function declaration and definition.

\$2.19