C Programming Assignment 2

Question 1

Print all numbers in the range 100 − 0 (inclusive) in steps of 4 in descending order.

Example Output

100

96

92

88

.

.

. 0

Rubrics

• Using a loop (4 points).

• Printing in descending order (2 points).

• Printing in steps of 4 (2 points).

• Printing the given range (2 points).

 

Question 2

Read in an integer userinput (?). Printthesquare of eachnumber in the range 0 − ? (excluding

?).

Example Output

Enter n: 5

0ˆ2 = 0

1ˆ2 = 1

2ˆ2 = 4

3ˆ2 = 9

4ˆ2 = 16

Rubrics

• Using scanf (3 points).

• Using a loop (3 points).

• Printing ? at every iteration up to ? < ? (2 points).

• Printing the square of ? (2 points).

 

Question 3

Read in an integer user input of numbers in the range 0 − 9 and create a logical statement that swaps numbers with their corresponding symbol on the keyboard. If the number is out of range, print Out of Range.

Example Output

Enter number: 4

 

4 is $ Enter number: 7

7 is &

Enter number: 20 20 is Out of Range

Rubrics

• Using scanf (2 points).

• Using a logical statement (4 points).

• Swapping and printing numbers with their symbols (2 points).

• Handling and printing out of range values (2 points).

 

Question 4

Write a program that checks whether a person is allowed into an PG13 rated movie in a theatre. Only

one of the following two conditions is required for admittance:

• The person is at least 13 years of age.

• The person has parental supervision.

– 1: yes

– 0: no

Example Output

Input age: 12

Has parental supervision: 1 // 1 for yes

The person is allowed to watch. Input age: 13

Has parental supervision: 0 // 0 for no

The person is allowed to watch. Input age: 12

Has parental supervision: 0 // 0 for no

The person is NOT allowed to watch.

 

Rubrics

• Using scanf (2 points).

• Using logical statement (if/switch) (4 points).

• Using relational operators (2 points).

• Output is correct (2 points).

Need a custom answer at your budget?

This assignment has been answered 5 times in private sessions.

© 2024 Codify Tutor. All rights reserved