SlideShare a Scribd company logo
Page | i
Author
Ts. Mohd At-Tarmizi Bin Abu Hassan
Publisher
Page | ii
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 | iii
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 | iv
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 | v
77 EXAMPLES & EXERCISES OF C PROGRAMMING
iii
iv
v
1-16
17-35
36-49
50-60
61-77
78-79
80-86
Acknowledgements
Preface
Table of Contents
77 Examples of C Programming - Sequences Structure
77 Examples of C Programming - Selection Structure
77 Examples of C Programming - Repetition Structure
77 Examples of C Programming - Array
77 Examples of C Programming - Function
77 Examples of C Programming - Pointer
77 Examples of C Programming - Applications
77 Exercices of C Programming
References and Further Studies
87-103
vi
1
77 EXAMPLES & EXERCISES OF C PROGRAMMING
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
2
77 EXAMPLES & EXERCISES OF C PROGRAMMING
3 - ComputerGenie_getch.c source code
3 - ComputerGenie_getch.c output file
4 - ComputerGenie_getchar.c source code
4 - ComputerGenie_getchar.c ouput file
3
77 EXAMPLES & EXERCISES OF C PROGRAMMING
5 - ComputerGenie_getche.c source code
5 - ComputerGenie_getche.c output file
4
77 EXAMPLES & EXERCISES OF C PROGRAMMING
6 - Understand_Various_Of_Data_Types.c source code
6 - Understand_Various_Of_Data_Types.c output file
5
77 EXAMPLES & EXERCISES OF C PROGRAMMING
7 - Draw_Guns_in_the_specified_format.c source code
7 - Draw_Guns_in_the_specified_format.c output file
6
77 EXAMPLES & EXERCISES OF C PROGRAMMING
8 - Basic_Calculator.c source code
8 - Basic_Calculator.c output file
7
77 EXAMPLES & EXERCISES OF C PROGRAMMING
9 - Puts_and_gets_name_age.c source code
9 - Puts_and_gets_name_age.c output file
8
77 EXAMPLES & EXERCISES OF C PROGRAMMING
10 - Understanding_Precedence.c source code
10 - Understanding_Precedence.c output file
9
77 EXAMPLES & EXERCISES OF C PROGRAMMING
11 - Undertanding_Relational_Operator.c source code
11 - Undertanding_Relational_Operator.c output file
10
77 EXAMPLES & EXERCISES OF C PROGRAMMING
12 - Compound_Assignment.c source code
12 - Compound_Assignment.c output file
11
77 EXAMPLES & EXERCISES OF C PROGRAMMING
13 - AverageTemperature.c source code
13 - AverageTemperature.c output file
12
77 EXAMPLES & EXERCISES OF C PROGRAMMING
14 - CalculateCircleCircumferenceandArea.c source code
14 - CalculateCircleCircumferenceandArea.c output file
13
77 EXAMPLES & EXERCISES OF C PROGRAMMING
15 - CalculateCubicAreaAndVolume.c source code
15 - CalculateCubicAreaAndVolume.c output file
16 - CalculateMonthlySaving.c source code
16 - CalculateMonthlySaving.c output file
14
77 EXAMPLES & EXERCISES OF C PROGRAMMING
17 - ConvertDistance.c source code
17 - ConvertDistance.c output file
18 - ConvertTemperatureCentigradetoFahrenheit.c source code
18 - ConvertTemperatureCentigradetoFahrenheit.c output file
15
77 EXAMPLES & EXERCISES OF C PROGRAMMING
19 - ConvertTemperatureFahrenheittoCentigrade.c source code
19 - ConvertTemperatureFahrenheittoCentigrade.c output file
20 - Base_and_Power.c source code
20 - Base_and_Power.c output file
16
77 EXAMPLES & EXERCISES OF C PROGRAMMING
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
17
77 EXAMPLES & EXERCISES OF C PROGRAMMING
2. SELECTION STRUCTURE
23 - If under age.c source code
23 - If under age.c output file
18
77 EXAMPLES & EXERCISES OF C PROGRAMMING
24 - AgeForVoting.c source code
24 - AgeForVoting.c output file
A. If statement output file
B. Else statement output file
19
77 EXAMPLES & EXERCISES OF C PROGRAMMING
25 - Find_Largest_Number.c source code
25 - Find_Largest_Number.c output file
20
77 EXAMPLES & EXERCISES OF C PROGRAMMING
26 - Find_Smallest_Number.c source code
26 - Find_Smallest_Number.c output file
21
77 EXAMPLES & EXERCISES OF C PROGRAMMING
27 - Odd_or_Even_Number.c source code
27 - Odd_or_Even_Number.c output file
22
77 EXAMPLES & EXERCISES OF C PROGRAMMING
28 - Switch_Case_Fruits_Integer.c source code
28 - Switch_Case_Fruits_Integer.c output file
23
77 EXAMPLES & EXERCISES OF C PROGRAMMING
29 - Switch_Case_Blood_Type.c source code
29 - Switch_Case_Blood_Type.c output file
24
77 EXAMPLES & EXERCISES OF C PROGRAMMING
30 – Nested_If_Voted.c source code
30 – Nested_If_Voted.c output file
25
77 EXAMPLES & EXERCISES OF C PROGRAMMING
31 - Gred_Examination_System.c source code
31 - Gred_Examination_System.c output file
26
77 EXAMPLES & EXERCISES OF C PROGRAMMING
32 – Blood_Pressure.c source code
32 – Blood_Pressure.c output file
27
77 EXAMPLES & EXERCISES OF C PROGRAMMING
33 - Body_Mass_Index.c source code
28
77 EXAMPLES & EXERCISES OF C PROGRAMMING
33 - Body_Mass_Index.c output file
29
77 EXAMPLES & EXERCISES OF C PROGRAMMING
34 - Fever_Check.c source code
34 - Fever_Check.c output file
30
77 EXAMPLES & EXERCISES OF C PROGRAMMING
35 - Calculate_Electricity_Bill.c source code
35 - Calculate_Electricity_Bill.c output file
31
77 EXAMPLES & EXERCISES OF C PROGRAMMING
36 - Calculate_Water_Bill.c source code
32
77 EXAMPLES & EXERCISES OF C PROGRAMMING
36 - Calculate_Water_Bill.c output file
33
77 EXAMPLES & EXERCISES OF C PROGRAMMING
37 - Calculate_Resistor_Value.c source code
34
77 EXAMPLES & EXERCISES OF C PROGRAMMING
35
77 EXAMPLES & EXERCISES OF C PROGRAMMING
37 - Calculate_Resistor_Value.c output file
36
77 EXAMPLES & EXERCISES OF C PROGRAMMING
3. REPETITION STRUCTURE
38 - While_Statement_CountDown_In_Ascending_Order.c source code
38 - While_Statement_CountDown_In_Ascending_Order.c output file
37
77 EXAMPLES & EXERCISES OF C PROGRAMMING
39 - While_Statement_CountDown_In_Descending_Order.c source code
39 - While_Statement_CountDown_In_Descending_Order.c output file
38
77 EXAMPLES & EXERCISES OF C PROGRAMMING
40 - Do_While_Statement_CountDown_In_Ascending_Order.c source code
40 - Do_While_Statement_CountDown_In_Ascending_Order.c ouput file
39
77 EXAMPLES & EXERCISES OF C PROGRAMMING
41 - Do_While_Statement_CountDown_In_Ascending_Order.c source code
41 - Do_While_Statement_CountDown_In_Ascending_Order.c output file
40
77 EXAMPLES & EXERCISES OF C PROGRAMMING
42 - For_Statement_CountDown_In_Ascending_Order.c source code
42 - For_Statement_CountDown_In_Ascending_Order.c output file
41
77 EXAMPLES & EXERCISES OF C PROGRAMMING
43 - For_Statement_CountDown_In_Descending_Order.c source code
43 - For_Statement_CountDown_In_Descending_Order.c output file
42
77 EXAMPLES & EXERCISES OF C PROGRAMMING
44 - Pre_Test_While_Statement.c source code
44 - Pre_Test_While_Statement.c output file
43
77 EXAMPLES & EXERCISES OF C PROGRAMMING
45 - Post_Test_Do_While_Statement.c source code
45 - Post_Test_Do_While_Statement.c output file
44
77 EXAMPLES & EXERCISES OF C PROGRAMMING
46 - Average_Marks_For_Statement.c source code
46 - Average_Marks_For_Statement.c output file
45
77 EXAMPLES & EXERCISES OF C PROGRAMMING
47 - Reverse_Number.c source code
47 - Reverse_Number.c utput file
46
77 EXAMPLES & EXERCISES OF C PROGRAMMING
48 - Countdown_In_Descending_Order.c source code
48 - Countdown_In_Descending_Order.c output file
47
77 EXAMPLES & EXERCISES OF C PROGRAMMING
49 - Electrical_Power_Calculator.c source code
48
77 EXAMPLES & EXERCISES OF C PROGRAMMING
49
77 EXAMPLES & EXERCISES OF C PROGRAMMING
49 - Electrical_Power_Calculator.c output file
50
77 EXAMPLES & EXERCISES OF C PROGRAMMING
4. ARRAY
50 - 1Array_Initializing.c source code
50 - 1Array_Initializing.c output file
51
77 EXAMPLES & EXERCISES OF C PROGRAMMING
51 - 2Array_with_Loop.c source code
51 - 2Array_with_Loop.c output file
52
77 EXAMPLES & EXERCISES OF C PROGRAMMING
52 - 3Array_Two_Dimentional.c source code
52 - 3Array_Two_Dimentional.c output file
53
77 EXAMPLES & EXERCISES OF C PROGRAMMING
53 - 4Passing_Arrays_as_Function_Arguments.c source code
53 - 4Passing_Arrays_as_Function_Arguments.c output file
54
77 EXAMPLES & EXERCISES OF C PROGRAMMING
54 - 5Array_Find_Average.c source code
54 - 5Array_Find_Average.c output file
55
77 EXAMPLES & EXERCISES OF C PROGRAMMING
55 - 6Array_Find_Total.c source code
55 - 6Array_Find_Total.c output file
56
77 EXAMPLES & EXERCISES OF C PROGRAMMING
56 - 7Array_Total_Daily_Rainfall_For_A_Weeks.c source code
56 - 7Array_Total_Daily_Rainfall_For_A_Weeks.c output file
57
77 EXAMPLES & EXERCISES OF C PROGRAMMING
57 - 8Array_Average_Marks.c source code
57 - 8Array_Average_Marks.c output file
58
77 EXAMPLES & EXERCISES OF C PROGRAMMING
58 - 9Array_Find_Event_Number.c source code
59
77 EXAMPLES & EXERCISES OF C PROGRAMMING
58 - 9Array_Find_Event_Number.c output file
60
77 EXAMPLES & EXERCISES OF C PROGRAMMING
59 - 10Array_Find_Average_For_Two_Dimentional_Marks.c source code
59 - 10Array_Find_Average_For_Two_Dimentional_Marks.c output file
61
77 EXAMPLES & EXERCISES OF C PROGRAMMING
5. FUNCTION.
60 - 1Function_User_Defined.c source code
62
77 EXAMPLES & EXERCISES OF C PROGRAMMING
60 - 1Function_User_Defined.c output file
61 - 2Function_Find_Minimum_Value.c source code
61 - 2Function_Find_Minimum_Value.c output file
63
77 EXAMPLES & EXERCISES OF C PROGRAMMING
62 - 3Function_Call_By_Value.c source code
62 - 3Function_Call_By_Value.c output file
64
77 EXAMPLES & EXERCISES OF C PROGRAMMING
63 - 4Function_Call_By_Reference.c source code
63 - 4Function_Call_By_Reference.c output file
65
77 EXAMPLES & EXERCISES OF C PROGRAMMING
64 - 5Function_Annual_Income.c source code
64 - 5Function_Annual_Income.c output file
66
77 EXAMPLES & EXERCISES OF C PROGRAMMING
65 - 6Function_Calculate Volume For Sphere.c source code
65 - 6Function_Calculate Volume For Sphere.c output file
67
77 EXAMPLES & EXERCISES OF C PROGRAMMING
66 - 7Function_Draw_Face.c source code
68
77 EXAMPLES & EXERCISES OF C PROGRAMMING
66 - 7Function_Draw_Face.c output file
69
77 EXAMPLES & EXERCISES OF C PROGRAMMING
67 - 8Function_Choose_Face_To_Draw.c source code
70
77 EXAMPLES & EXERCISES OF C PROGRAMMING
71
77 EXAMPLES & EXERCISES OF C PROGRAMMING
72
77 EXAMPLES & EXERCISES OF C PROGRAMMING
67 - 8Function_Choose_Face_To_Draw.c output file
73
77 EXAMPLES & EXERCISES OF C PROGRAMMING
68 - 9Function_Draw_House.c source code
74
77 EXAMPLES & EXERCISES OF C PROGRAMMING
68 - 9Function_Draw_House.c output file
75
77 EXAMPLES & EXERCISES OF C PROGRAMMING
69 - 10Function_Pass_by_Value.c source code
69 - 10Function_Pass_by_Value.c output file
76
77 EXAMPLES & EXERCISES OF C PROGRAMMING
70 - 11Function_Sum1.c source code
70 - 11Function_Sum1.c output file
77
77 EXAMPLES & EXERCISES OF C PROGRAMMING
71 - 12Function_Sum2.c source code
71 - 12Function_Sum2.c output file
78
77 EXAMPLES & EXERCISES OF C PROGRAMMING
6. POINTER.
72 - Pointer.c source code
72 - Pointer.c output file
73 - Pointer_AccessThevalueofavariables.c source code
73 - Pointer_AccessThevalueofavariables.c output file
79
77 EXAMPLES & EXERCISES OF C PROGRAMMING
74 - Pointer_ReferenceOperatorandDereferenceOperator.c source code
74 - Pointer_ReferenceOperatorandDereferenceOperator.c output file
80
77 EXAMPLES & EXERCISES OF C PROGRAMMING
7. APPLICATIONS.
75 - Calculate_Paracetamol_Dose.c source code
75 - Calculate_Paracetamol_Dose.c output file
81
77 EXAMPLES & EXERCISES OF C PROGRAMMING
76 - Games_Tic_Tac_Toe.c source code
82
77 EXAMPLES & EXERCISES OF C PROGRAMMING
83
77 EXAMPLES & EXERCISES OF C PROGRAMMING
76 - Games_Tic_Tac_Toe.c output file
84
77 EXAMPLES & EXERCISES OF C PROGRAMMING
77 - Ohms Law Calculator.c source code
85
77 EXAMPLES & EXERCISES OF C PROGRAMMING
86
77 EXAMPLES & EXERCISES OF C PROGRAMMING
77 - Ohms Law Calculator.c output file
87
77 EXAMPLES & EXERCISES OF C PROGRAMMING
77 EXERCISES OF C PROGRAMMING
1. The term 'programming language' is defined as
A. The language which machines communicate with machines
B. The language which machines communicate with humans
C. The language which humans communicate with computers
D. The special language for machines
2. Algorithm is defined as
A. The sequence of steps required to provide a solution to a problem
B. The sequence to provide a solution to a case
C. The instructions to get the output
D. Combined the instructions in a program
3. Alphabetic and numeric combinations, however they must all begin with
an alphabet. Only the underscore (_) may be used as a special character.
This statement is referring to
A. Constants
B. Variables
C. Identifiers
D. Keywords
4. Select the program's output from the following:
A. 3
B. 4
C. 5
D. 6
5. In a "switch-case" statement, which of the following cannot be checked?
A. enum
B. integer
C. character
D. float
#include<stdio.h>
int main()
{
int i=1;
i= 2+2*i++;
printf(“%d”,i);
return 0;
}
88
77 EXAMPLES & EXERCISES OF C PROGRAMMING
6. Daniel wants to design a program to generate the eligible age to apply for a driving license.
Choose the appropriate control structure to solve problem above.
A. if - else
B. switch - case
C. for
D. do - while
7. "Repeat the section of your program based on a specified number of times."
The above statement is referring to
A. for
B. if
C. if - else
D. switch case
8. What will the program's results be?
A. 0 1 2 3 4 5
B. 0 1 2 3 4
C. 1 2 3 4
D. 1 2 3 4 5
9. Identify the elements in planning process.
i. Calculation
ii. Process
iii. Input
iv. Output
v. Progress
A. i, ii, and iii only
B. ii, iii and iv only
C. iii and iv only
D. All of the above.
10. If a is an integer variable, after modulus operation a = 5%2; will return a value
A. 0
B. 1
C. 2
D. 2.5
#include<stdio.h>
int main ()
{
int i=0;
for (i=1; i<=5; i++)
{printf ("%d", i);}
return 0;
}
89
77 EXAMPLES & EXERCISES OF C PROGRAMMING
11. What is the definition of programme?
A. A person, who designs, writes and tests computer programs.
B. A computer tool that allows a programmer to write commands in a format.
C. A translated code that the computer can understand and execute.
D. A specific set of ordered operations for a computer to perform.
12. The programming language structure or grammar refers to the C ____________________.
A. Syntax
B. Grammar
C. Language
D. Semantics
13. C programming is considered a ___________________.
A. Low-Level Language
B. Intermediate Level Language
C. High-Level Language
D. Assembly Language
14. _________________ are closer to human languages and easier to understand. It is also used
to develop complex applications.
A. Machine Language
B. Intermediate Level Language
C. High-Level Language
D. Assembly Language
15. Below are the processes that take place in the pre-processor and compiler during a
compilation process EXCEPT?
A. Replace macro with code
B. Comments removal
C. Generates an executable file
D. Include header file
16. Below are acceptable definitions of a programme EXCEPT?
A. A well-organized set of guidelines that specify to the computer what to do and how
to do it.
B. A numbered list of instructions to perform some task usually used to outline the
general steps in an algorithm without having to write the actual codes.
C. A set of source code written in computer programming language meant for a specific
task and executed in certain sequences.
D. A text file containing sequences of C semantics put together according to C syntax.
90
77 EXAMPLES & EXERCISES OF C PROGRAMMING
17. _________________ contains only numerical information and is difficult to be understood
by a human.
A. Machine Language
B. Intermediate Level Language
C. High-Level Language
D. Assembly Language
18. C programs are converted into machine language with the help of _________________.
A. an interpreter
B. an editor
C. a builder
D. a compiler
19. Which of the following statements BEST describes a programmer?
A. A person who designs computer programs.
B. A person who composes instructions for the computer system.
C. A person who designs, writes, and test computer programs.
D. A person who test computer programs.
20. The vocabulary of commands understood by humans and can be converted into machine
language refers to the C ______________.
A. syntax
B. grammar
C. language
D. Semantics
21. Listed below are the types of programming EXCEPT?
A. Modular programming
B. Structured programing
C. High-Level programming
D. Object-Oriented programming
22. The programming tool uses linked symbols to show the sequence of steps needed to solve a
programming problem.
A. Pseudocode
B. Flowchart
C. Input Process Output (IPO) Table
D. Grid Table
23. Name the flowchart symbol below.
A. Terminal
B. On-page Connector
C. Off-page Connector
D. Subroutine
91
77 EXAMPLES & EXERCISES OF C PROGRAMMING
24. Which of the following descriptions of the algorithm is FALSE?
A. Algorithm must specify a list of steps to be executed in the right order.
B. Algorithm can be represented using a flowchart or pseudocode.
C. Algorithm can be described as a procedure to solve a problem.
D. Algorithm is written only after the coding has been completed.
25. The following pseudocode is an example of a ____________ structure.
A. Selection
B. Nested
C. Sequential
D. Looping
26. Does the following flowchart represent which control structure in C programming?
A. if else selection structure
B. switch case selection structure
C. while repetition structure
D. do while repetition structure
27. Which of the following benefits of flowcharting is NOT one?
A. Easier coding
B. Facilitates debugging
C. Effective analysis
D. Improper documentation
START
1. Get Num
2. While(Num>0)
2.1 Sum = Sum + Num
2.2 Num = Num + 1
1. Display Sum
STOP
92
77 EXAMPLES & EXERCISES OF C PROGRAMMING
28. _______________ is a compact and informal text-based approach to documenting an
algorithm.
A. Histogram
B. Pseudocode
C. Flowchart
D. IPO Chart
29. In a flowchart, the geometrical figure shown below represents.
A. Input and output
B. Subroutine
C. Decisions
D. Process
30. The following pseudocode is an example of a ____________ structure.
A. Selection
B. Sequential
C. Repetition
D. Nested
31. Identify which control structure does the following flowchart represent in C programming?
A. if selection structure
B. switch case selection structure
C. if else selection structure
D. nested if selection structure
32. Which of the following is an advantage of pseudocode?
A. Difficult for beginners to follow the program logic.
B. Facilitates analysis, coding, and debugging processes.
C. No standardized style or format.
D. It does not provide a visual representation of an algorithm.
START
1. Read A, B
2. Calculate Sum = A + B
3. Display Sum
STOP
93
77 EXAMPLES & EXERCISES OF C PROGRAMMING
33. Which of the following is NOT a fundamental C data type?
A. float
B. real
C. int
D. char
34. Which of the following does NOT qualify as a valid bit representation?
A. 8 bit
B. 24 bit
C. 32 bit
D. 64 bit
35. Identify the INCORRECT statement for 'identifier'.
A. An identifier cannot begin with a digit.
B. There cannot be any spaces between the characters in an identifier.
C. Other than underscore, no special symbols may be used.
D. Reserved words can be used as identification.
36. What are the names of the entities whose values can be modified?
A. Tokens
B. Variables
C. Constants
D. Modules
37. If ‘a’ is an integer variable, then a = 5/2; will return a value of?
A. 2.5
B. 0
C. 2
D. 3
38. What should be the appropriate value returned to the operating system when a programme
has successfully run?
A. -1
B. 0
C. 1
D. Programs do not return a value.
39. Which one function is a need for all C programmes?
A. system ()
B. program ()
C. main ()
D. start ()
40. What type of punctuation marks the start and end of a code block?
A. { }
B. ( )
C. [ ]
D. BEGIN and END
94
77 EXAMPLES & EXERCISES OF C PROGRAMMING
41. Every statement in C programming must end with a _________________.
A. period (.)
B. backslash ()
C. colon (:)
D. semicolon (;)
42. Text enclosed in /* */ in a C program ____________________.
A. gives instructions to the processor
B. declares memory requirements.
C. is ignored by the C compiler.
D. causes a syntax error.
43. Which of the following are INVALID identifiers?
i. R3D3
ii. per-capita
iii. phone#
iv. ice_cream
v. 91_gold
A. i, ii, iv, v
B. i, iv
C. ii, iii, v
D. ii, iv, v
44. What is the correct statement to declare a constant?
A. constant a=10;
B. const int a=10
C. const int a=10;
D. #define a 10;
45. An identifier in C ___________________________.
A. cannot contain any uppercase or lowercase letters, decimal digits, or the underscore
character
B. can have no more than one embedded blank
C. can begin with an underscore
D. can be a reserved word
46. Pick one of the following symbols that can be included in a variable name.
A. asterisk (*)
B. hashtag (#)
C. addition (+)
D. underscore (_)
47. Select the operator with the lowest level of precedence.
A. +
B. =
C. *
D. <
95
77 EXAMPLES & EXERCISES OF C PROGRAMMING
48. Which of the following identifiers is INVALID?
i. integer
ii. printf
iii. Net-total
iv. _sum
A. i, ii and iii
B. i, iii, and iv
C. ii and iii
D. i, ii, iii, iv
49. Which of the following is a selection statement?
A. switch case
B. while
C. do while
D. for
50. Does the following flowchart represent which control structure in C?
A. if else selection structure
B. switch case selection structure
C. while repetition structure
D. for repetition structure
51. Which of the following statements best describes 'Pseudocode'?
A. A graphical depiction of data, information, and workflow that details problem-
solving steps by connecting specific symbols to flow lines.
B. Defined as a numbered list of instructions to perform some task usually used to
outline the general steps in an algorithm without having to write actual code.
C. Before the actual programme development, a list of measures to address problems
is established to ensure that the right problem-solving technique is used.
D. It lists the inputs, the outputs, and the procedures that must be taken to convert the
inputs into the outputs of a programme.
96
77 EXAMPLES & EXERCISES OF C PROGRAMMING
52. Which of the statements below, best describes a ‘Flow Chart’?
A. A graphical representation of data, information, and workflow using certain symbols
that are connected to flow lines to describe the instructions carried out in problem
solving.
B. It is simply a numbered list of instructions to perform some task, usually used to
outline the general steps in an algorithm, without having to write actual code.
C. A list of measures to solve problems is created before the actual program code to
make sure the correct problem solution method is used.
D. Identify the program’s inputs, its outputs, and the processing steps that required
transforming the inputs into outputs.
53. X is best described as a / an …………………………
A. Operator
B. Constant
C. Variable
D. Data type
54. To print out a and b below, which of the following printf() statement should be used?
A. printf (“ %f %d”, a, b);
B. printf (“ %f %x”, a, b);
C. printf (“ %f %s”, a, b);
D. printf (“ %f %c”, a, b);
X is a memory location in a computer’s memory to store varied value data.
To indicate the memory location, each X should be given a unique name.
X is the symbol that represents a memory location.
#include <stdio.h>
void main ()
{
float a=3.14;
unsigned char b=’&’;
}
97
77 EXAMPLES & EXERCISES OF C PROGRAMMING
55. What is the output of the programme based on the flowchart below?
Start
Insert grade =50
If intGrade >= 70
Message to print:
“Passing grade”
Stop
Message to print:
“Failing grade”
No
Yes
A. Message to print: “Failing grade.”
B. Message to print: “Passing grade.”
C. Failing grade.
D. Passing grade.
56. In the documentation of a programming project, a programmer needs to determine the
functions, variables, and formulas that he should use. This statement refers to:
A. Determining requirement specification process
B. Writing project proposal, flowchart, and project plan process
C. Making specification test process
D. Writing source code process
57. Compiler generates ______________ file.
A. Executable code
B. Object code
C. Assembly code
D. None of the above
58. How many different outcomes can be achieved with a single if-else statement?
A. 1
B. 2
C. 3
D. 4
98
77 EXAMPLES & EXERCISES OF C PROGRAMMING
59. The infinite looping CANNOT be avoided by a _______________ if the condition is missing in
a ‘for’ loop.
A. continue statement
B. go to statement
C. return statement
D. break statement
60. Which of the following statements are TRUE about while loop statements?
i. It is also known as exit controlled loop.
ii. It is an entry-controlled loop.
iii. The body of loop will be executed at least once even if the test condition is false.
iv. If test condition is initially false the body of loop is not executed at all.
A. i and iii
B. i and iv
C. ii and iii
D. ii and iv
61. An example of a C programme would be?
A. Variables
B. Statements
C. Functions
D. All of the above
62. Name the flowchart symbol below.
A. Terminal
B. On-page connector
C. Subroutine
D. Off-page connector
99
77 EXAMPLES & EXERCISES OF C PROGRAMMING
63. What would be the output for the following C code?
A. It will print nothing
B. 0
C. -2
D. Compile error
64. Which control structure does the following flowchart represents in C?
A. if
B. if else
C. nested if else
D. switch case
65. What must be done to prevent failing from one case to the next?
A. stop;
B. break;
C. end;
D. A semicolon
#include<stdio.h>
int main()
{
int a=2;
if (a==2)
{
a=-a+2<1;
printf(“%d”,a);
}
else
{
break;
}
}
100
77 EXAMPLES & EXERCISES OF C PROGRAMMING
66. What does the following code produce?
A. One
B. Zero
C. Hello World
D. ZeroHello World
67. Which of the following is NOT a looping statement?
A. for
B. do while
C. while
D. repeat until
68. The following flowchart represents which control structure in C?
A. if else selection structure
B. switch case selection structure
C. while repetition structure
D. do while repetition structure
69. What is the meaning of the code block while (x>100)?
A. While x is less than one hundred
B. While x is greater than one hundred
C. While x is equal to one hundred
D. While is wishes
int x=0;
switch(x)
{
case 1: printf(“One”);break;
case 0: printf(“Zero”); break;
case 2: printf(“Hello World”);break;
}
101
77 EXAMPLES & EXERCISES OF C PROGRAMMING
70. Imprudent use of goto statement leads to?
A. Unstructured spaghetti code
B. Infinite loop
C. Break statement
D. None of the above
71. What is the final value of x when the code for (int x=0; x<10; x++) is executed?
A. 0
B. 1
C. 9
D. 10
72. What do you think will be the output of the code below?
A. 0 1 2 3 4 5 6 7 8 9
B. 0 1 2 3 4 5 6 7 8
C. 1 2 3 4 5 6 7 8 9
D. 1 2 3 4 5 6 7 8 9
73. Which of the following statements are TRUE about Do-While loop statements?
i. It is also known as exit controlled loop
ii. It is an entry controlled loop.
iii. The body of loop will be executed at least once even if the test condition is false.
iv. If test condition is initially false the body of loop is not executed at all.
A. i and iii
B. i and iv
C. ii and iii
D. ii and iv
#include<stdio.h>
void main()
{
int i;
for(i=0;i<10;i++)
printf("%d ",i);
}
102
77 EXAMPLES & EXERCISES OF C PROGRAMMING
74. In the code below, how many times is the value of x tested?
A. 2
B. 4
C. 3
D. 1
75. Choose the value of NUM so that the output would be 6:
A. 2
B. 4
C. 6
D. 8
76. What does function mean?
A. A function is a collection of statements that carry out a particular activity.
B. Function is the fundamental modular unit. Typically, a function is created to
carry out a specified duty.
C. Function is a block of code that performs a specific task. It is reusable and
has a name.
D. All of the above.
77. Any C program
A. Needs input data
B. Need not contain any function
C. Must contain at least one function
D. None of the above
#include <stdio.h>
int main()
{
int x = 0;
while (x<3)
{
x++;
printf("DEC20012 Is Fun!n");
}
}
#include<stdio.h>
int main()
{
int i;
for(i=6;i>4;i-=2)
{
printf("%d", i);
}
}}
103
77 EXAMPLES & EXERCISES OF C PROGRAMMING
Answer.
1. C
2. A
3. C
4. B
5. D
6. A
7. A
8. D
9. B
10. B
11. D
12. A
13. C
14. C
15. C
16. B
17. A
18. D
19. C
20. D
21. C
22. B
23. C
24. D
25. D
26. C
27. D
28. B
29. C
30. B
31. C
32. B
33. B
34. B
35. D
36. B
37. C
38. B
39. C
40. A
41. D
42. C
43. C
44. C
45. C
46. D
47. B
48. C
49. A
50. D
51. B
52. A
53. C
54. D
55. C
56. B
57. B
58. B
59. A
60. D
61. D
62. B
63. D
64. A
65. B
66. B
67. D
68. C
69. A
70. A
71. D
72. A
73. A
74. B
75. C
76. D
77. C
Page | vi
77 EXAMPLES & EXERCISES OF C PROGRAMMING
1. Gookin, D. (2013). Beginning Programming with C for Dummies. John Wiley & Sons.
2. Hooi, Y. K. (2018). Fundamentals of Programming Polytechnic Series. Oxford Fajar
Sdn. Bhd.
3. Kanetkar, Y. (2016). Let us C (15th
Edition). BPB publications.
4. Klemens, B. (2015). 21st Century C (Second Edition). O'Reilly Published.
5. Kochan, S. G. (2013). Programming in objective-C. Pearson Education India.
6. Learn-c.org. (n.d.). learn-c.org free interactive C tutorial. Retrieved from learn-c.org:
https://www.learn-c.org/
7. Programiz. (n.d.). Parewa Labs Pvt. Ltd. Retrieved from Learn C Programming:
https://www.programiz.com/c-programming
8. Allain, A. (2019). Cprogramming.com. Retrieved from Learn C and C++
Programming: https://www.cprogramming.com/
02 Ebook 77 Examples and Exercises of C Programming.pdf

More Related Content

Similar to 02 Ebook 77 Examples and Exercises of C Programming.pdf

Cross-Project Build Co-change Prediction
Cross-Project Build Co-change PredictionCross-Project Build Co-change Prediction
Cross-Project Build Co-change Prediction
Shane McIntosh
 
Computer programming all chapters
Computer programming all chaptersComputer programming all chapters
Computer programming all chapters
Ibrahim Elewah
 
intro-slides.pdf very important for computer science students
intro-slides.pdf very important for computer science studentsintro-slides.pdf very important for computer science students
intro-slides.pdf very important for computer science students
sairevanth504
 
Embedded Software Engineer
Embedded Software EngineerEmbedded Software Engineer
Embedded Software Engineer
Vasu Patel
 
Embedded Software Engineer
Embedded Software EngineerEmbedded Software Engineer
Embedded Software Engineer
Vasu Patel
 

Similar to 02 Ebook 77 Examples and Exercises of C Programming.pdf (20)

Components of CI/CD in DevOps
Components of CI/CD in DevOpsComponents of CI/CD in DevOps
Components of CI/CD in DevOps
 
Masters_Thesis_FINAL_COPY
Masters_Thesis_FINAL_COPYMasters_Thesis_FINAL_COPY
Masters_Thesis_FINAL_COPY
 
Cross-Project Build Co-change Prediction
Cross-Project Build Co-change PredictionCross-Project Build Co-change Prediction
Cross-Project Build Co-change Prediction
 
Staroletov Design by Contract, verification of Cyber-physical systems
Staroletov Design by Contract, verification of Cyber-physical systemsStaroletov Design by Contract, verification of Cyber-physical systems
Staroletov Design by Contract, verification of Cyber-physical systems
 
Computer programming all chapters
Computer programming all chaptersComputer programming all chapters
Computer programming all chapters
 
Ds C+++Programming+From+Problem+Analysis+to+Program+Design+_5th+Edition_+book...
Ds C+++Programming+From+Problem+Analysis+to+Program+Design+_5th+Edition_+book...Ds C+++Programming+From+Problem+Analysis+to+Program+Design+_5th+Edition_+book...
Ds C+++Programming+From+Problem+Analysis+to+Program+Design+_5th+Edition_+book...
 
Rajeshkanna_Resume
Rajeshkanna_ResumeRajeshkanna_Resume
Rajeshkanna_Resume
 
intro-slides.pdf very important for computer science students
intro-slides.pdf very important for computer science studentsintro-slides.pdf very important for computer science students
intro-slides.pdf very important for computer science students
 
Mi0033
Mi0033Mi0033
Mi0033
 
Mechatronics engineer
Mechatronics engineerMechatronics engineer
Mechatronics engineer
 
Dell Technologies D-VBX-DY-A-24 Exam Study Guide with Sample Questions
Dell Technologies D-VBX-DY-A-24 Exam Study Guide with Sample QuestionsDell Technologies D-VBX-DY-A-24 Exam Study Guide with Sample Questions
Dell Technologies D-VBX-DY-A-24 Exam Study Guide with Sample Questions
 
Duane martin 11 21 14 resume
Duane martin 11 21 14 resumeDuane martin 11 21 14 resume
Duane martin 11 21 14 resume
 
Embedded Software Engineer
Embedded Software EngineerEmbedded Software Engineer
Embedded Software Engineer
 
Embedded Software Engineer
Embedded Software EngineerEmbedded Software Engineer
Embedded Software Engineer
 
65_96195_CC112_2014_1__1_1_week1.pdf
65_96195_CC112_2014_1__1_1_week1.pdf65_96195_CC112_2014_1__1_1_week1.pdf
65_96195_CC112_2014_1__1_1_week1.pdf
 
Cmps 260, fall 2021 programming assignment #3 (125 points)
Cmps 260, fall 2021 programming assignment #3 (125 points)Cmps 260, fall 2021 programming assignment #3 (125 points)
Cmps 260, fall 2021 programming assignment #3 (125 points)
 
What to do as simulation expert
What to do as simulation expertWhat to do as simulation expert
What to do as simulation expert
 
Aie module3 handout
Aie module3 handoutAie module3 handout
Aie module3 handout
 
Sql xp 09
Sql xp 09Sql xp 09
Sql xp 09
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdf
 

Recently uploaded

Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
Avinash Rai
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff
17thcssbs2
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
ashishpaul799
 
Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
SaadHumayun7
 

Recently uploaded (20)

Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdfPost Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdf
 
The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...
 
IATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdffIATP How-to Foreign Travel May 2024.pdff
IATP How-to Foreign Travel May 2024.pdff
 
Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17Features of Video Calls in the Discuss Module in Odoo 17
Features of Video Calls in the Discuss Module in Odoo 17
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
 
Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
 

02 Ebook 77 Examples and Exercises of C Programming.pdf

  • 1.
  • 2. Page | i Author Ts. Mohd At-Tarmizi Bin Abu Hassan Publisher
  • 3. Page | ii 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.
  • 4. Page | iii 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
  • 5. Page | iv 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!”
  • 6. Page | v 77 EXAMPLES & EXERCISES OF C PROGRAMMING iii iv v 1-16 17-35 36-49 50-60 61-77 78-79 80-86 Acknowledgements Preface Table of Contents 77 Examples of C Programming - Sequences Structure 77 Examples of C Programming - Selection Structure 77 Examples of C Programming - Repetition Structure 77 Examples of C Programming - Array 77 Examples of C Programming - Function 77 Examples of C Programming - Pointer 77 Examples of C Programming - Applications 77 Exercices of C Programming References and Further Studies 87-103 vi
  • 7. 1 77 EXAMPLES & EXERCISES OF C PROGRAMMING 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
  • 8. 2 77 EXAMPLES & EXERCISES OF C PROGRAMMING 3 - ComputerGenie_getch.c source code 3 - ComputerGenie_getch.c output file 4 - ComputerGenie_getchar.c source code 4 - ComputerGenie_getchar.c ouput file
  • 9. 3 77 EXAMPLES & EXERCISES OF C PROGRAMMING 5 - ComputerGenie_getche.c source code 5 - ComputerGenie_getche.c output file
  • 10. 4 77 EXAMPLES & EXERCISES OF C PROGRAMMING 6 - Understand_Various_Of_Data_Types.c source code 6 - Understand_Various_Of_Data_Types.c output file
  • 11. 5 77 EXAMPLES & EXERCISES OF C PROGRAMMING 7 - Draw_Guns_in_the_specified_format.c source code 7 - Draw_Guns_in_the_specified_format.c output file
  • 12. 6 77 EXAMPLES & EXERCISES OF C PROGRAMMING 8 - Basic_Calculator.c source code 8 - Basic_Calculator.c output file
  • 13. 7 77 EXAMPLES & EXERCISES OF C PROGRAMMING 9 - Puts_and_gets_name_age.c source code 9 - Puts_and_gets_name_age.c output file
  • 14. 8 77 EXAMPLES & EXERCISES OF C PROGRAMMING 10 - Understanding_Precedence.c source code 10 - Understanding_Precedence.c output file
  • 15. 9 77 EXAMPLES & EXERCISES OF C PROGRAMMING 11 - Undertanding_Relational_Operator.c source code 11 - Undertanding_Relational_Operator.c output file
  • 16. 10 77 EXAMPLES & EXERCISES OF C PROGRAMMING 12 - Compound_Assignment.c source code 12 - Compound_Assignment.c output file
  • 17. 11 77 EXAMPLES & EXERCISES OF C PROGRAMMING 13 - AverageTemperature.c source code 13 - AverageTemperature.c output file
  • 18. 12 77 EXAMPLES & EXERCISES OF C PROGRAMMING 14 - CalculateCircleCircumferenceandArea.c source code 14 - CalculateCircleCircumferenceandArea.c output file
  • 19. 13 77 EXAMPLES & EXERCISES OF C PROGRAMMING 15 - CalculateCubicAreaAndVolume.c source code 15 - CalculateCubicAreaAndVolume.c output file 16 - CalculateMonthlySaving.c source code 16 - CalculateMonthlySaving.c output file
  • 20. 14 77 EXAMPLES & EXERCISES OF C PROGRAMMING 17 - ConvertDistance.c source code 17 - ConvertDistance.c output file 18 - ConvertTemperatureCentigradetoFahrenheit.c source code 18 - ConvertTemperatureCentigradetoFahrenheit.c output file
  • 21. 15 77 EXAMPLES & EXERCISES OF C PROGRAMMING 19 - ConvertTemperatureFahrenheittoCentigrade.c source code 19 - ConvertTemperatureFahrenheittoCentigrade.c output file 20 - Base_and_Power.c source code 20 - Base_and_Power.c output file
  • 22. 16 77 EXAMPLES & EXERCISES OF C PROGRAMMING 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
  • 23. 17 77 EXAMPLES & EXERCISES OF C PROGRAMMING 2. SELECTION STRUCTURE 23 - If under age.c source code 23 - If under age.c output file
  • 24. 18 77 EXAMPLES & EXERCISES OF C PROGRAMMING 24 - AgeForVoting.c source code 24 - AgeForVoting.c output file A. If statement output file B. Else statement output file
  • 25. 19 77 EXAMPLES & EXERCISES OF C PROGRAMMING 25 - Find_Largest_Number.c source code 25 - Find_Largest_Number.c output file
  • 26. 20 77 EXAMPLES & EXERCISES OF C PROGRAMMING 26 - Find_Smallest_Number.c source code 26 - Find_Smallest_Number.c output file
  • 27. 21 77 EXAMPLES & EXERCISES OF C PROGRAMMING 27 - Odd_or_Even_Number.c source code 27 - Odd_or_Even_Number.c output file
  • 28. 22 77 EXAMPLES & EXERCISES OF C PROGRAMMING 28 - Switch_Case_Fruits_Integer.c source code 28 - Switch_Case_Fruits_Integer.c output file
  • 29. 23 77 EXAMPLES & EXERCISES OF C PROGRAMMING 29 - Switch_Case_Blood_Type.c source code 29 - Switch_Case_Blood_Type.c output file
  • 30. 24 77 EXAMPLES & EXERCISES OF C PROGRAMMING 30 – Nested_If_Voted.c source code 30 – Nested_If_Voted.c output file
  • 31. 25 77 EXAMPLES & EXERCISES OF C PROGRAMMING 31 - Gred_Examination_System.c source code 31 - Gred_Examination_System.c output file
  • 32. 26 77 EXAMPLES & EXERCISES OF C PROGRAMMING 32 – Blood_Pressure.c source code 32 – Blood_Pressure.c output file
  • 33. 27 77 EXAMPLES & EXERCISES OF C PROGRAMMING 33 - Body_Mass_Index.c source code
  • 34. 28 77 EXAMPLES & EXERCISES OF C PROGRAMMING 33 - Body_Mass_Index.c output file
  • 35. 29 77 EXAMPLES & EXERCISES OF C PROGRAMMING 34 - Fever_Check.c source code 34 - Fever_Check.c output file
  • 36. 30 77 EXAMPLES & EXERCISES OF C PROGRAMMING 35 - Calculate_Electricity_Bill.c source code 35 - Calculate_Electricity_Bill.c output file
  • 37. 31 77 EXAMPLES & EXERCISES OF C PROGRAMMING 36 - Calculate_Water_Bill.c source code
  • 38. 32 77 EXAMPLES & EXERCISES OF C PROGRAMMING 36 - Calculate_Water_Bill.c output file
  • 39. 33 77 EXAMPLES & EXERCISES OF C PROGRAMMING 37 - Calculate_Resistor_Value.c source code
  • 40. 34 77 EXAMPLES & EXERCISES OF C PROGRAMMING
  • 41. 35 77 EXAMPLES & EXERCISES OF C PROGRAMMING 37 - Calculate_Resistor_Value.c output file
  • 42. 36 77 EXAMPLES & EXERCISES OF C PROGRAMMING 3. REPETITION STRUCTURE 38 - While_Statement_CountDown_In_Ascending_Order.c source code 38 - While_Statement_CountDown_In_Ascending_Order.c output file
  • 43. 37 77 EXAMPLES & EXERCISES OF C PROGRAMMING 39 - While_Statement_CountDown_In_Descending_Order.c source code 39 - While_Statement_CountDown_In_Descending_Order.c output file
  • 44. 38 77 EXAMPLES & EXERCISES OF C PROGRAMMING 40 - Do_While_Statement_CountDown_In_Ascending_Order.c source code 40 - Do_While_Statement_CountDown_In_Ascending_Order.c ouput file
  • 45. 39 77 EXAMPLES & EXERCISES OF C PROGRAMMING 41 - Do_While_Statement_CountDown_In_Ascending_Order.c source code 41 - Do_While_Statement_CountDown_In_Ascending_Order.c output file
  • 46. 40 77 EXAMPLES & EXERCISES OF C PROGRAMMING 42 - For_Statement_CountDown_In_Ascending_Order.c source code 42 - For_Statement_CountDown_In_Ascending_Order.c output file
  • 47. 41 77 EXAMPLES & EXERCISES OF C PROGRAMMING 43 - For_Statement_CountDown_In_Descending_Order.c source code 43 - For_Statement_CountDown_In_Descending_Order.c output file
  • 48. 42 77 EXAMPLES & EXERCISES OF C PROGRAMMING 44 - Pre_Test_While_Statement.c source code 44 - Pre_Test_While_Statement.c output file
  • 49. 43 77 EXAMPLES & EXERCISES OF C PROGRAMMING 45 - Post_Test_Do_While_Statement.c source code 45 - Post_Test_Do_While_Statement.c output file
  • 50. 44 77 EXAMPLES & EXERCISES OF C PROGRAMMING 46 - Average_Marks_For_Statement.c source code 46 - Average_Marks_For_Statement.c output file
  • 51. 45 77 EXAMPLES & EXERCISES OF C PROGRAMMING 47 - Reverse_Number.c source code 47 - Reverse_Number.c utput file
  • 52. 46 77 EXAMPLES & EXERCISES OF C PROGRAMMING 48 - Countdown_In_Descending_Order.c source code 48 - Countdown_In_Descending_Order.c output file
  • 53. 47 77 EXAMPLES & EXERCISES OF C PROGRAMMING 49 - Electrical_Power_Calculator.c source code
  • 54. 48 77 EXAMPLES & EXERCISES OF C PROGRAMMING
  • 55. 49 77 EXAMPLES & EXERCISES OF C PROGRAMMING 49 - Electrical_Power_Calculator.c output file
  • 56. 50 77 EXAMPLES & EXERCISES OF C PROGRAMMING 4. ARRAY 50 - 1Array_Initializing.c source code 50 - 1Array_Initializing.c output file
  • 57. 51 77 EXAMPLES & EXERCISES OF C PROGRAMMING 51 - 2Array_with_Loop.c source code 51 - 2Array_with_Loop.c output file
  • 58. 52 77 EXAMPLES & EXERCISES OF C PROGRAMMING 52 - 3Array_Two_Dimentional.c source code 52 - 3Array_Two_Dimentional.c output file
  • 59. 53 77 EXAMPLES & EXERCISES OF C PROGRAMMING 53 - 4Passing_Arrays_as_Function_Arguments.c source code 53 - 4Passing_Arrays_as_Function_Arguments.c output file
  • 60. 54 77 EXAMPLES & EXERCISES OF C PROGRAMMING 54 - 5Array_Find_Average.c source code 54 - 5Array_Find_Average.c output file
  • 61. 55 77 EXAMPLES & EXERCISES OF C PROGRAMMING 55 - 6Array_Find_Total.c source code 55 - 6Array_Find_Total.c output file
  • 62. 56 77 EXAMPLES & EXERCISES OF C PROGRAMMING 56 - 7Array_Total_Daily_Rainfall_For_A_Weeks.c source code 56 - 7Array_Total_Daily_Rainfall_For_A_Weeks.c output file
  • 63. 57 77 EXAMPLES & EXERCISES OF C PROGRAMMING 57 - 8Array_Average_Marks.c source code 57 - 8Array_Average_Marks.c output file
  • 64. 58 77 EXAMPLES & EXERCISES OF C PROGRAMMING 58 - 9Array_Find_Event_Number.c source code
  • 65. 59 77 EXAMPLES & EXERCISES OF C PROGRAMMING 58 - 9Array_Find_Event_Number.c output file
  • 66. 60 77 EXAMPLES & EXERCISES OF C PROGRAMMING 59 - 10Array_Find_Average_For_Two_Dimentional_Marks.c source code 59 - 10Array_Find_Average_For_Two_Dimentional_Marks.c output file
  • 67. 61 77 EXAMPLES & EXERCISES OF C PROGRAMMING 5. FUNCTION. 60 - 1Function_User_Defined.c source code
  • 68. 62 77 EXAMPLES & EXERCISES OF C PROGRAMMING 60 - 1Function_User_Defined.c output file 61 - 2Function_Find_Minimum_Value.c source code 61 - 2Function_Find_Minimum_Value.c output file
  • 69. 63 77 EXAMPLES & EXERCISES OF C PROGRAMMING 62 - 3Function_Call_By_Value.c source code 62 - 3Function_Call_By_Value.c output file
  • 70. 64 77 EXAMPLES & EXERCISES OF C PROGRAMMING 63 - 4Function_Call_By_Reference.c source code 63 - 4Function_Call_By_Reference.c output file
  • 71. 65 77 EXAMPLES & EXERCISES OF C PROGRAMMING 64 - 5Function_Annual_Income.c source code 64 - 5Function_Annual_Income.c output file
  • 72. 66 77 EXAMPLES & EXERCISES OF C PROGRAMMING 65 - 6Function_Calculate Volume For Sphere.c source code 65 - 6Function_Calculate Volume For Sphere.c output file
  • 73. 67 77 EXAMPLES & EXERCISES OF C PROGRAMMING 66 - 7Function_Draw_Face.c source code
  • 74. 68 77 EXAMPLES & EXERCISES OF C PROGRAMMING 66 - 7Function_Draw_Face.c output file
  • 75. 69 77 EXAMPLES & EXERCISES OF C PROGRAMMING 67 - 8Function_Choose_Face_To_Draw.c source code
  • 76. 70 77 EXAMPLES & EXERCISES OF C PROGRAMMING
  • 77. 71 77 EXAMPLES & EXERCISES OF C PROGRAMMING
  • 78. 72 77 EXAMPLES & EXERCISES OF C PROGRAMMING 67 - 8Function_Choose_Face_To_Draw.c output file
  • 79. 73 77 EXAMPLES & EXERCISES OF C PROGRAMMING 68 - 9Function_Draw_House.c source code
  • 80. 74 77 EXAMPLES & EXERCISES OF C PROGRAMMING 68 - 9Function_Draw_House.c output file
  • 81. 75 77 EXAMPLES & EXERCISES OF C PROGRAMMING 69 - 10Function_Pass_by_Value.c source code 69 - 10Function_Pass_by_Value.c output file
  • 82. 76 77 EXAMPLES & EXERCISES OF C PROGRAMMING 70 - 11Function_Sum1.c source code 70 - 11Function_Sum1.c output file
  • 83. 77 77 EXAMPLES & EXERCISES OF C PROGRAMMING 71 - 12Function_Sum2.c source code 71 - 12Function_Sum2.c output file
  • 84. 78 77 EXAMPLES & EXERCISES OF C PROGRAMMING 6. POINTER. 72 - Pointer.c source code 72 - Pointer.c output file 73 - Pointer_AccessThevalueofavariables.c source code 73 - Pointer_AccessThevalueofavariables.c output file
  • 85. 79 77 EXAMPLES & EXERCISES OF C PROGRAMMING 74 - Pointer_ReferenceOperatorandDereferenceOperator.c source code 74 - Pointer_ReferenceOperatorandDereferenceOperator.c output file
  • 86. 80 77 EXAMPLES & EXERCISES OF C PROGRAMMING 7. APPLICATIONS. 75 - Calculate_Paracetamol_Dose.c source code 75 - Calculate_Paracetamol_Dose.c output file
  • 87. 81 77 EXAMPLES & EXERCISES OF C PROGRAMMING 76 - Games_Tic_Tac_Toe.c source code
  • 88. 82 77 EXAMPLES & EXERCISES OF C PROGRAMMING
  • 89. 83 77 EXAMPLES & EXERCISES OF C PROGRAMMING 76 - Games_Tic_Tac_Toe.c output file
  • 90. 84 77 EXAMPLES & EXERCISES OF C PROGRAMMING 77 - Ohms Law Calculator.c source code
  • 91. 85 77 EXAMPLES & EXERCISES OF C PROGRAMMING
  • 92. 86 77 EXAMPLES & EXERCISES OF C PROGRAMMING 77 - Ohms Law Calculator.c output file
  • 93. 87 77 EXAMPLES & EXERCISES OF C PROGRAMMING 77 EXERCISES OF C PROGRAMMING 1. The term 'programming language' is defined as A. The language which machines communicate with machines B. The language which machines communicate with humans C. The language which humans communicate with computers D. The special language for machines 2. Algorithm is defined as A. The sequence of steps required to provide a solution to a problem B. The sequence to provide a solution to a case C. The instructions to get the output D. Combined the instructions in a program 3. Alphabetic and numeric combinations, however they must all begin with an alphabet. Only the underscore (_) may be used as a special character. This statement is referring to A. Constants B. Variables C. Identifiers D. Keywords 4. Select the program's output from the following: A. 3 B. 4 C. 5 D. 6 5. In a "switch-case" statement, which of the following cannot be checked? A. enum B. integer C. character D. float #include<stdio.h> int main() { int i=1; i= 2+2*i++; printf(“%d”,i); return 0; }
  • 94. 88 77 EXAMPLES & EXERCISES OF C PROGRAMMING 6. Daniel wants to design a program to generate the eligible age to apply for a driving license. Choose the appropriate control structure to solve problem above. A. if - else B. switch - case C. for D. do - while 7. "Repeat the section of your program based on a specified number of times." The above statement is referring to A. for B. if C. if - else D. switch case 8. What will the program's results be? A. 0 1 2 3 4 5 B. 0 1 2 3 4 C. 1 2 3 4 D. 1 2 3 4 5 9. Identify the elements in planning process. i. Calculation ii. Process iii. Input iv. Output v. Progress A. i, ii, and iii only B. ii, iii and iv only C. iii and iv only D. All of the above. 10. If a is an integer variable, after modulus operation a = 5%2; will return a value A. 0 B. 1 C. 2 D. 2.5 #include<stdio.h> int main () { int i=0; for (i=1; i<=5; i++) {printf ("%d", i);} return 0; }
  • 95. 89 77 EXAMPLES & EXERCISES OF C PROGRAMMING 11. What is the definition of programme? A. A person, who designs, writes and tests computer programs. B. A computer tool that allows a programmer to write commands in a format. C. A translated code that the computer can understand and execute. D. A specific set of ordered operations for a computer to perform. 12. The programming language structure or grammar refers to the C ____________________. A. Syntax B. Grammar C. Language D. Semantics 13. C programming is considered a ___________________. A. Low-Level Language B. Intermediate Level Language C. High-Level Language D. Assembly Language 14. _________________ are closer to human languages and easier to understand. It is also used to develop complex applications. A. Machine Language B. Intermediate Level Language C. High-Level Language D. Assembly Language 15. Below are the processes that take place in the pre-processor and compiler during a compilation process EXCEPT? A. Replace macro with code B. Comments removal C. Generates an executable file D. Include header file 16. Below are acceptable definitions of a programme EXCEPT? A. A well-organized set of guidelines that specify to the computer what to do and how to do it. B. A numbered list of instructions to perform some task usually used to outline the general steps in an algorithm without having to write the actual codes. C. A set of source code written in computer programming language meant for a specific task and executed in certain sequences. D. A text file containing sequences of C semantics put together according to C syntax.
  • 96. 90 77 EXAMPLES & EXERCISES OF C PROGRAMMING 17. _________________ contains only numerical information and is difficult to be understood by a human. A. Machine Language B. Intermediate Level Language C. High-Level Language D. Assembly Language 18. C programs are converted into machine language with the help of _________________. A. an interpreter B. an editor C. a builder D. a compiler 19. Which of the following statements BEST describes a programmer? A. A person who designs computer programs. B. A person who composes instructions for the computer system. C. A person who designs, writes, and test computer programs. D. A person who test computer programs. 20. The vocabulary of commands understood by humans and can be converted into machine language refers to the C ______________. A. syntax B. grammar C. language D. Semantics 21. Listed below are the types of programming EXCEPT? A. Modular programming B. Structured programing C. High-Level programming D. Object-Oriented programming 22. The programming tool uses linked symbols to show the sequence of steps needed to solve a programming problem. A. Pseudocode B. Flowchart C. Input Process Output (IPO) Table D. Grid Table 23. Name the flowchart symbol below. A. Terminal B. On-page Connector C. Off-page Connector D. Subroutine
  • 97. 91 77 EXAMPLES & EXERCISES OF C PROGRAMMING 24. Which of the following descriptions of the algorithm is FALSE? A. Algorithm must specify a list of steps to be executed in the right order. B. Algorithm can be represented using a flowchart or pseudocode. C. Algorithm can be described as a procedure to solve a problem. D. Algorithm is written only after the coding has been completed. 25. The following pseudocode is an example of a ____________ structure. A. Selection B. Nested C. Sequential D. Looping 26. Does the following flowchart represent which control structure in C programming? A. if else selection structure B. switch case selection structure C. while repetition structure D. do while repetition structure 27. Which of the following benefits of flowcharting is NOT one? A. Easier coding B. Facilitates debugging C. Effective analysis D. Improper documentation START 1. Get Num 2. While(Num>0) 2.1 Sum = Sum + Num 2.2 Num = Num + 1 1. Display Sum STOP
  • 98. 92 77 EXAMPLES & EXERCISES OF C PROGRAMMING 28. _______________ is a compact and informal text-based approach to documenting an algorithm. A. Histogram B. Pseudocode C. Flowchart D. IPO Chart 29. In a flowchart, the geometrical figure shown below represents. A. Input and output B. Subroutine C. Decisions D. Process 30. The following pseudocode is an example of a ____________ structure. A. Selection B. Sequential C. Repetition D. Nested 31. Identify which control structure does the following flowchart represent in C programming? A. if selection structure B. switch case selection structure C. if else selection structure D. nested if selection structure 32. Which of the following is an advantage of pseudocode? A. Difficult for beginners to follow the program logic. B. Facilitates analysis, coding, and debugging processes. C. No standardized style or format. D. It does not provide a visual representation of an algorithm. START 1. Read A, B 2. Calculate Sum = A + B 3. Display Sum STOP
  • 99. 93 77 EXAMPLES & EXERCISES OF C PROGRAMMING 33. Which of the following is NOT a fundamental C data type? A. float B. real C. int D. char 34. Which of the following does NOT qualify as a valid bit representation? A. 8 bit B. 24 bit C. 32 bit D. 64 bit 35. Identify the INCORRECT statement for 'identifier'. A. An identifier cannot begin with a digit. B. There cannot be any spaces between the characters in an identifier. C. Other than underscore, no special symbols may be used. D. Reserved words can be used as identification. 36. What are the names of the entities whose values can be modified? A. Tokens B. Variables C. Constants D. Modules 37. If ‘a’ is an integer variable, then a = 5/2; will return a value of? A. 2.5 B. 0 C. 2 D. 3 38. What should be the appropriate value returned to the operating system when a programme has successfully run? A. -1 B. 0 C. 1 D. Programs do not return a value. 39. Which one function is a need for all C programmes? A. system () B. program () C. main () D. start () 40. What type of punctuation marks the start and end of a code block? A. { } B. ( ) C. [ ] D. BEGIN and END
  • 100. 94 77 EXAMPLES & EXERCISES OF C PROGRAMMING 41. Every statement in C programming must end with a _________________. A. period (.) B. backslash () C. colon (:) D. semicolon (;) 42. Text enclosed in /* */ in a C program ____________________. A. gives instructions to the processor B. declares memory requirements. C. is ignored by the C compiler. D. causes a syntax error. 43. Which of the following are INVALID identifiers? i. R3D3 ii. per-capita iii. phone# iv. ice_cream v. 91_gold A. i, ii, iv, v B. i, iv C. ii, iii, v D. ii, iv, v 44. What is the correct statement to declare a constant? A. constant a=10; B. const int a=10 C. const int a=10; D. #define a 10; 45. An identifier in C ___________________________. A. cannot contain any uppercase or lowercase letters, decimal digits, or the underscore character B. can have no more than one embedded blank C. can begin with an underscore D. can be a reserved word 46. Pick one of the following symbols that can be included in a variable name. A. asterisk (*) B. hashtag (#) C. addition (+) D. underscore (_) 47. Select the operator with the lowest level of precedence. A. + B. = C. * D. <
  • 101. 95 77 EXAMPLES & EXERCISES OF C PROGRAMMING 48. Which of the following identifiers is INVALID? i. integer ii. printf iii. Net-total iv. _sum A. i, ii and iii B. i, iii, and iv C. ii and iii D. i, ii, iii, iv 49. Which of the following is a selection statement? A. switch case B. while C. do while D. for 50. Does the following flowchart represent which control structure in C? A. if else selection structure B. switch case selection structure C. while repetition structure D. for repetition structure 51. Which of the following statements best describes 'Pseudocode'? A. A graphical depiction of data, information, and workflow that details problem- solving steps by connecting specific symbols to flow lines. B. Defined as a numbered list of instructions to perform some task usually used to outline the general steps in an algorithm without having to write actual code. C. Before the actual programme development, a list of measures to address problems is established to ensure that the right problem-solving technique is used. D. It lists the inputs, the outputs, and the procedures that must be taken to convert the inputs into the outputs of a programme.
  • 102. 96 77 EXAMPLES & EXERCISES OF C PROGRAMMING 52. Which of the statements below, best describes a ‘Flow Chart’? A. A graphical representation of data, information, and workflow using certain symbols that are connected to flow lines to describe the instructions carried out in problem solving. B. It is simply a numbered list of instructions to perform some task, usually used to outline the general steps in an algorithm, without having to write actual code. C. A list of measures to solve problems is created before the actual program code to make sure the correct problem solution method is used. D. Identify the program’s inputs, its outputs, and the processing steps that required transforming the inputs into outputs. 53. X is best described as a / an ………………………… A. Operator B. Constant C. Variable D. Data type 54. To print out a and b below, which of the following printf() statement should be used? A. printf (“ %f %d”, a, b); B. printf (“ %f %x”, a, b); C. printf (“ %f %s”, a, b); D. printf (“ %f %c”, a, b); X is a memory location in a computer’s memory to store varied value data. To indicate the memory location, each X should be given a unique name. X is the symbol that represents a memory location. #include <stdio.h> void main () { float a=3.14; unsigned char b=’&’; }
  • 103. 97 77 EXAMPLES & EXERCISES OF C PROGRAMMING 55. What is the output of the programme based on the flowchart below? Start Insert grade =50 If intGrade >= 70 Message to print: “Passing grade” Stop Message to print: “Failing grade” No Yes A. Message to print: “Failing grade.” B. Message to print: “Passing grade.” C. Failing grade. D. Passing grade. 56. In the documentation of a programming project, a programmer needs to determine the functions, variables, and formulas that he should use. This statement refers to: A. Determining requirement specification process B. Writing project proposal, flowchart, and project plan process C. Making specification test process D. Writing source code process 57. Compiler generates ______________ file. A. Executable code B. Object code C. Assembly code D. None of the above 58. How many different outcomes can be achieved with a single if-else statement? A. 1 B. 2 C. 3 D. 4
  • 104. 98 77 EXAMPLES & EXERCISES OF C PROGRAMMING 59. The infinite looping CANNOT be avoided by a _______________ if the condition is missing in a ‘for’ loop. A. continue statement B. go to statement C. return statement D. break statement 60. Which of the following statements are TRUE about while loop statements? i. It is also known as exit controlled loop. ii. It is an entry-controlled loop. iii. The body of loop will be executed at least once even if the test condition is false. iv. If test condition is initially false the body of loop is not executed at all. A. i and iii B. i and iv C. ii and iii D. ii and iv 61. An example of a C programme would be? A. Variables B. Statements C. Functions D. All of the above 62. Name the flowchart symbol below. A. Terminal B. On-page connector C. Subroutine D. Off-page connector
  • 105. 99 77 EXAMPLES & EXERCISES OF C PROGRAMMING 63. What would be the output for the following C code? A. It will print nothing B. 0 C. -2 D. Compile error 64. Which control structure does the following flowchart represents in C? A. if B. if else C. nested if else D. switch case 65. What must be done to prevent failing from one case to the next? A. stop; B. break; C. end; D. A semicolon #include<stdio.h> int main() { int a=2; if (a==2) { a=-a+2<1; printf(“%d”,a); } else { break; } }
  • 106. 100 77 EXAMPLES & EXERCISES OF C PROGRAMMING 66. What does the following code produce? A. One B. Zero C. Hello World D. ZeroHello World 67. Which of the following is NOT a looping statement? A. for B. do while C. while D. repeat until 68. The following flowchart represents which control structure in C? A. if else selection structure B. switch case selection structure C. while repetition structure D. do while repetition structure 69. What is the meaning of the code block while (x>100)? A. While x is less than one hundred B. While x is greater than one hundred C. While x is equal to one hundred D. While is wishes int x=0; switch(x) { case 1: printf(“One”);break; case 0: printf(“Zero”); break; case 2: printf(“Hello World”);break; }
  • 107. 101 77 EXAMPLES & EXERCISES OF C PROGRAMMING 70. Imprudent use of goto statement leads to? A. Unstructured spaghetti code B. Infinite loop C. Break statement D. None of the above 71. What is the final value of x when the code for (int x=0; x<10; x++) is executed? A. 0 B. 1 C. 9 D. 10 72. What do you think will be the output of the code below? A. 0 1 2 3 4 5 6 7 8 9 B. 0 1 2 3 4 5 6 7 8 C. 1 2 3 4 5 6 7 8 9 D. 1 2 3 4 5 6 7 8 9 73. Which of the following statements are TRUE about Do-While loop statements? i. It is also known as exit controlled loop ii. It is an entry controlled loop. iii. The body of loop will be executed at least once even if the test condition is false. iv. If test condition is initially false the body of loop is not executed at all. A. i and iii B. i and iv C. ii and iii D. ii and iv #include<stdio.h> void main() { int i; for(i=0;i<10;i++) printf("%d ",i); }
  • 108. 102 77 EXAMPLES & EXERCISES OF C PROGRAMMING 74. In the code below, how many times is the value of x tested? A. 2 B. 4 C. 3 D. 1 75. Choose the value of NUM so that the output would be 6: A. 2 B. 4 C. 6 D. 8 76. What does function mean? A. A function is a collection of statements that carry out a particular activity. B. Function is the fundamental modular unit. Typically, a function is created to carry out a specified duty. C. Function is a block of code that performs a specific task. It is reusable and has a name. D. All of the above. 77. Any C program A. Needs input data B. Need not contain any function C. Must contain at least one function D. None of the above #include <stdio.h> int main() { int x = 0; while (x<3) { x++; printf("DEC20012 Is Fun!n"); } } #include<stdio.h> int main() { int i; for(i=6;i>4;i-=2) { printf("%d", i); } }}
  • 109. 103 77 EXAMPLES & EXERCISES OF C PROGRAMMING Answer. 1. C 2. A 3. C 4. B 5. D 6. A 7. A 8. D 9. B 10. B 11. D 12. A 13. C 14. C 15. C 16. B 17. A 18. D 19. C 20. D 21. C 22. B 23. C 24. D 25. D 26. C 27. D 28. B 29. C 30. B 31. C 32. B 33. B 34. B 35. D 36. B 37. C 38. B 39. C 40. A 41. D 42. C 43. C 44. C 45. C 46. D 47. B 48. C 49. A 50. D 51. B 52. A 53. C 54. D 55. C 56. B 57. B 58. B 59. A 60. D 61. D 62. B 63. D 64. A 65. B 66. B 67. D 68. C 69. A 70. A 71. D 72. A 73. A 74. B 75. C 76. D 77. C
  • 110. Page | vi 77 EXAMPLES & EXERCISES OF C PROGRAMMING 1. Gookin, D. (2013). Beginning Programming with C for Dummies. John Wiley & Sons. 2. Hooi, Y. K. (2018). Fundamentals of Programming Polytechnic Series. Oxford Fajar Sdn. Bhd. 3. Kanetkar, Y. (2016). Let us C (15th Edition). BPB publications. 4. Klemens, B. (2015). 21st Century C (Second Edition). O'Reilly Published. 5. Kochan, S. G. (2013). Programming in objective-C. Pearson Education India. 6. Learn-c.org. (n.d.). learn-c.org free interactive C tutorial. Retrieved from learn-c.org: https://www.learn-c.org/ 7. Programiz. (n.d.). Parewa Labs Pvt. Ltd. Retrieved from Learn C Programming: https://www.programiz.com/c-programming 8. Allain, A. (2019). Cprogramming.com. Retrieved from Learn C and C++ Programming: https://www.cprogramming.com/