0% found this document useful (0 votes)
567 views2 pages

Lab Exercise Chapter 4

This document outlines 5 exercises for a C programming lab. The exercises include: 1) Printing values with different precisions and justifications, 2) Identifying and correcting an error in a sample code, 3) Writing a program to calculate the sum of even integers from 2 to 30 using a for loop, 4) Writing programs to print two patterns using for loops and printf statements, 5) Trying out sample code for printing a total grade. The objective is for students to familiarize themselves with for loops and switch statements. The instructor may provide hints and more exercises if time allows.

Uploaded by

Mia Ghee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
567 views2 pages

Lab Exercise Chapter 4

This document outlines 5 exercises for a C programming lab. The exercises include: 1) Printing values with different precisions and justifications, 2) Identifying and correcting an error in a sample code, 3) Writing a program to calculate the sum of even integers from 2 to 30 using a for loop, 4) Writing programs to print two patterns using for loops and printf statements, 5) Trying out sample code for printing a total grade. The objective is for students to familiarize themselves with for loops and switch statements. The instructor may provide hints and more exercises if time allows.

Uploaded by

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

Lab Exercise (Chapter 4)

Exercise 1.
Print the value 333.546372 in a field width of 15 characters with
precisions of 1, 2, 3, 4 and 5. Right justify the output. What are the
five values that print? What should you do if you want to print Left
justify output?
Tips:
printf(%15.1f\n, 333.546372);
printf(%-15.1f\n, 333.546372);
Exercise 2.
Create a C program with the code as below and run it. Do you able
to identify the error? Explain and correct it.

Exercise 3.
(4.12 Calculating the Sum of Even Integers)
Write a program that calculates and prints the sum of the even
integers from 2 to 30, using a single for loop statement.
Exercise 4.
(4.16 Triangle Printing Program)
Write a program that prints the following patterns separately. Use
for loops to generate the patterns. All asterisks (*) should be
printed by a single printf statement of the form printf (*);
[Hint: the second pattern requires that each line begin with an
appropriate number of blanks. And, you will need two for loops
nested]
First pattern:

Second pattern:

Exercise 5.
(Additional Exercise)
Try out the exercise of printing the total grade, sample code in the
Chapter 4 lecture slide Page 58 61. Observe the result.

Objective of this lab exercise:


1. Let student familiarize with the usage of the for looping statement.
2. Let student familiarize with the usage of the switch statement.

Notes to instructor:
1. Instructor can give further guidelines or hints on Exercise 4.
2. Further exercises can be given if time permits

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy