Author
Ts. Mohd At-Tarmizi Bin Abu Hassan
Publisher
Page | i
77 EXAMPLES & EXERCISES OF C PROGRAMMING
77 Examples & Exercises of C Programming
© 2022 Politeknik Sultan Idris Shah
Toutes droits réservés. Without the author's explicit written consent, no portion
of this book may be duplicated, saved for later retrieval, or converted into any form or by
any method, including mechanical, electronic, refilming and recording, etc.
The views or opinions expressed in this release do not necessarily reflect
official policy, and the publishers and authors of this publication are not responsible for
any losses incurred by parties that act or refrain from acting as a result of information in this
publication.
Perpustakaan Negara Malaysia Cataloguing-in-Publication Data
Mohd. At-Tarmizi Abu Hassan, Ts., 1985-
77 EXAMPLES & EXERCISES OF C PROGRAMMING /
Author Ts. Mohd At-Tarmizi Bin Abu Hassan.
Mode of access: Internet
eISBN 978-967-2860-38-9
1. C (Computer program language).
2. Programming languages (Electronic computers).
3. Government publications--Malaysia.
4. Electronic books.
I. Title.
005.133
Published by:
Politeknik Sultan Idris Shah,
Sungai Lang,
45100 Sungai Air Tawar,
Selangor Darul Ehsan.
No. Tel: 03 3280 6200
No. Fax: 03 3280 6400
Website: https://psis.mypolycc.edu.my/index.php/interaktif/
penerbitan @ Ts. Mohd At-Tarmizi Bin Abu Hassan.
Page | ii
77 EXAMPLES & EXERCISES OF C PROGRAMMING
I would like to acknowledgement the assistance and encouragement of our families, friends
and top management of Politeknik Sultan Idris Shah who have actively contributed to the
successful publication of this book.
Ts. Mohd At-Tarmizi Bin Abu Hassan
Page | iii
77 EXAMPLES & EXERCISES OF C PROGRAMMING
This book is dedicated to all students of
Electrical Engineering at the polytechnic who
take the subject DEC20012 – Fundamental
Programming. The content is designed to
enhance C programming understanding and
skills through variations of examples and
exercises. “Practice makes perfect!”
Page | iv
77 EXAMPLES & EXERCISES OF C PROGRAMMING
Acknowledgements iii
Preface iv
Table of Contents v
77 Examples of C Programming - Sequences Structure 1-16
77 Examples of C Programming - Selection Structure 17-35
77 Examples of C Programming - Repetition Structure 36-49
77 Examples of C Programming - Array 50-60
77 Examples of C Programming - Function 61-77
77 Examples of C Programming - Pointer 78-79
77 Examples of C Programming - Applications 80-86
77 Exercices of C Programming 87-103
References and Further Studies vi
Page | v
77 EXAMPLES & EXERCISES OF C PROGRAMMING 1
77 EXAMPLES OF C PROGRAMMING
1. SEQUENCE STRUCTURE
1 - HelloWorld.c source code
1 - HelloWorld.c output file
2 - WelcomeToJKEPSIS.c source code
2 - WelcomeToJKEPSIS.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 2
3 - ComputerGenie_getch.c source code
3 - ComputerGenie_getch.c output file
4 - ComputerGenie_getchar.c source code
4 - ComputerGenie_getchar.c ouput file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 3
5 - ComputerGenie_getche.c source code
5 - ComputerGenie_getche.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 4
6 - Understand_Various_Of_Data_Types.c source code
6 - Understand_Various_Of_Data_Types.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 5
7 - Draw_Guns_in_the_specified_format.c source code
7 - Draw_Guns_in_the_specified_format.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 6
8 - Basic_Calculator.c source code
8 - Basic_Calculator.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 7
9 - Puts_and_gets_name_age.c source code
9 - Puts_and_gets_name_age.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 8
10 - Understanding_Precedence.c source code
10 - Understanding_Precedence.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 9
11 - Undertanding_Relational_Operator.c source code
11 - Undertanding_Relational_Operator.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 10
12 - Compound_Assignment.c source code
12 - Compound_Assignment.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 11
13 - AverageTemperature.c source code
13 - AverageTemperature.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 12
14 - CalculateCircleCircumferenceandArea.c source code
14 - CalculateCircleCircumferenceandArea.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 13
15 - CalculateCubicAreaAndVolume.c source code
15 - CalculateCubicAreaAndVolume.c output file
16 - CalculateMonthlySaving.c source code
16 - CalculateMonthlySaving.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 14
17 - ConvertDistance.c source code
17 - ConvertDistance.c output file
18 - ConvertTemperatureCentigradetoFahrenheit.c source code
18 - ConvertTemperatureCentigradetoFahrenheit.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 15
19 - ConvertTemperatureFahrenheittoCentigrade.c source code
19 - ConvertTemperatureFahrenheittoCentigrade.c output file
20 - Base_and_Power.c source code
20 - Base_and_Power.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 16
21 - Square_Root.c source code
21 - Square_Root.c output file
22 - Bigger_or_Smaller_or_Equal.c source code
22 - Bigger_or_Smaller_or_Equal.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 17
2. SELECTION STRUCTURE
23 - If under age.c source code
23 - If under age.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 18
24 - AgeForVoting.c source code
24 - AgeForVoting.c output file
A. If statement output file
B. Else statement output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 19
25 - Find_Largest_Number.c source code
25 - Find_Largest_Number.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 20
26 - Find_Smallest_Number.c source code
26 - Find_Smallest_Number.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 21
27 - Odd_or_Even_Number.c source code
27 - Odd_or_Even_Number.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 22
28 - Switch_Case_Fruits_Integer.c source code
28 - Switch_Case_Fruits_Integer.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 23
29 - Switch_Case_Blood_Type.c source code
29 - Switch_Case_Blood_Type.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 24
30 – Nested_If_Voted.c source code
30 – Nested_If_Voted.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 25
31 - Gred_Examination_System.c source code
31 - Gred_Examination_System.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 26
32 – Blood_Pressure.c source code
32 – Blood_Pressure.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 27
33 - Body_Mass_Index.c source code
77 EXAMPLES & EXERCISES OF C PROGRAMMING 28
33 - Body_Mass_Index.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 29
34 - Fever_Check.c source code
34 - Fever_Check.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 30
35 - Calculate_Electricity_Bill.c source code
35 - Calculate_Electricity_Bill.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 31
36 - Calculate_Water_Bill.c source code
77 EXAMPLES & EXERCISES OF C PROGRAMMING 32
36 - Calculate_Water_Bill.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 33
37 - Calculate_Resistor_Value.c source code
77 EXAMPLES & EXERCISES OF C PROGRAMMING 34
77 EXAMPLES & EXERCISES OF C PROGRAMMING 35
37 - Calculate_Resistor_Value.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 36
3. REPETITION STRUCTURE
38 - While_Statement_CountDown_In_Ascending_Order.c source code
38 - While_Statement_CountDown_In_Ascending_Order.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 37
39 - While_Statement_CountDown_In_Descending_Order.c source code
39 - While_Statement_CountDown_In_Descending_Order.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 38
40 - Do_While_Statement_CountDown_In_Ascending_Order.c source code
40 - Do_While_Statement_CountDown_In_Ascending_Order.c ouput file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 39
41 - Do_While_Statement_CountDown_In_Ascending_Order.c source code
41 - Do_While_Statement_CountDown_In_Ascending_Order.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 40
42 - For_Statement_CountDown_In_Ascending_Order.c source code
42 - For_Statement_CountDown_In_Ascending_Order.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 41
43 - For_Statement_CountDown_In_Descending_Order.c source code
43 - For_Statement_CountDown_In_Descending_Order.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 42
44 - Pre_Test_While_Statement.c source code
44 - Pre_Test_While_Statement.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 43
45 - Post_Test_Do_While_Statement.c source code
45 - Post_Test_Do_While_Statement.c output file
77 EXAMPLES & EXERCISES OF C PROGRAMMING 44
46 - Average_Marks_For_Statement.c source code
46 - Average_Marks_For_Statement.c output file