0% found this document useful (0 votes)
101 views

Computer 12 Class Notes (MCQS)

Uploaded by

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

Computer 12 Class Notes (MCQS)

Uploaded by

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

[Ch#1] Data Basics 27 Computer Science Part-II

Q1. Fill in the blanks


1. DBMS stands for Database Management System.
2. A record is a collection of related fields.
3. A file is a collection of related records.
4. Before processing the data is recorded in transaction files.
5. A database is a collection of logically related data.
6. The data definitions are stored in data dictionary.
7. SQL stands for Structured Query Language.
8. Hierarchical data model has the general shape of an organizational chart.
9. Data is a collection of facts, figures and statistics.
10. Processed data is called information.
Q2. Select the correct option
1. Which of the following represents a collection of concepts that are used to
describe the structure of a database?
a) Data warehouse b) Data structure
c) Data model d) Data type
2. Which of the following data model is more flexible?
a) Network data model b) Hierarchical data model
c) Relational data model d) Object data model
3. Which of the following type of file require largest processing time?
a) Sequential file b) Random file
c) Indexed sequential file d) Direct access file
4. Which of the following may be a temporary file?
a) Master file b) Transaction file
c) Backup file d) None of these
5. SQL is a(n)
a) Unstructured Language b) Structured language
c) Object oriented language d) Software
6. A collection of raw facts and figures is called:
a) Data b) Information
c) Database d) Data capturing
[Ch#1] Data Basics 28 Computer Science Part-II
7. Which of the following is not related to data manipulation?
a) Summarizing b) Data capturing
c) Classifying d) Calculations
8.  represents an object:
a) Person b) Organization
c) An event d) All of these
9. The manipulated and processed data is called:
(a) Raw data (b) Information
(c) Object (d) None of these
10. A series of actions that are performed on raw data achieve the required objective
and results are called:
(a) Operation (b) Data processing
(c) Processes (d) Both (a) and (b)
11. In  activity data is collected and recorded:
(a) Data capturing (b) Data Manipulating
(c) Managing result (d) None of these
12. In a school the record of cricket and hockey team organized into two groups is
referred as
a) Classifying b) Summarizing
c) Sorting d) Searching
13. A set of related characters that represent a unit of data is called
a) File b) Record
c) Field d) Database
14. A set of related fields that represent a unit of data is called
a) File b) Record
c) Field d) Database
15. A set of related records that represent a unit of data is called
a) File b) Record
c) Field d) Database
[Ch#1] Data Basics 29 Computer Science Part-II
16. A set of related files that represent a unit of data is called
a) File b) Record
c) Field d) Database
17. Which of the following refers to the correctness and consistency of data?
a) Data Independence b) Data Integration
c) Data Integrity d) Data Structure
18. Which of the following database model has the shape like and organizational
chart?
a) Network Model b) Hierarchical Model
c) Relational Model d) Data Model
19. In a college, organizing the record of Science and Arts students into two groups,
this activity is referred to as
(a) Sorting (b) Summarizing
(c) Classifying (d) None of these
20. The process of arranging data in a proper order is called:
(a) Sorting (b) Summarizing
(c) Classifying (d) Data capturing
21. Storage and retrieval of data is related to:
(a) Data capturing (b) Data Manipulation
(c) Managing output result (d) None of these
22. The process of making duplicate copies of output result is called:
(a) Storage and retrieval (b) Reproduction
(c) backup copy (d) Data processing
23.  is related to managing output result:
(a) Storage and retrieval (b) Communications
(c) Reproduction (d) All of these
24. Communicating the information through internet is related to:
(a) Managing output result (b) Data capturing
(c) Data Manipulation (d) None of these
25. The term “inverted tree” is used in
a) Network Model b) Hierarchical Model
c) Relational Model d) None of above
[Ch#1] Data Basics 30 Computer Science Part-II
26. The separation of the data structure of database from the application program is
called.
a) Data Independence b) Data Integration
c) Data Integrity d) Data Model
27. Which of the following data models is the most commonly used.
a) Hierarchical Model b) Network Model
c) Relational Model d) None of above
28. Which of the following is a computerized record keeping system?
a) Data system b) Database
c) File System d) DBMS
29. DBA Stands for
a) Data Business Adminstrator b) Database Administrator
c) Data Basic Applicaiton d) Database Application
30. Which of the following are the components of DBMS?
a) Hardware b) Software
c) Personnel d) All of above
31. Which of the following contain data definitions?
a) Data Dictionary b) Database
c) Database Integrity d) All of above
32. Which of the following is a query language?
a) DBMS b) Utilities
c) Report d) SQL
33. The name of person represents:
(a) Field (b) Record
(c) File (d) None of these
34. A complete information about a particular entity represents a:
(a) Field (b) Record
(c) File (d) None of these
35. Each column in a table represents a:
(a) Field (b) Record
(c) File (d) None of these
[Ch#1] Data Basics 31 Computer Science Part-II
36. Each row of a table represents a:
(a) Field (b) Record
(c) File (d) None of these
37. A table with related records is referred to as:
(a) Field (b) Record
(c) File (d) None of these
38. The process of making the copy of original is called
a) Storage b) Retrieval
c) Backup d) None of above
39. Arrangement of data in a particular order is
a) Searching b) Sorting
c) Storing d) Summarizing
40. The file extension of a program file is
a) EXE b) Com
c) prog d) both a and b
41. Which is not true about data
a) Facts b) Figures
c) Meaningful d) Cannot be used for decision making
42. Using information managers can create
a) Useful Reports b) Graphs
c) Statistics d) All of Above
43. To convert data into information we need some
a) Input b) Output
c) Processing d) All of Above
44. Which one refers data capturing
a) Getting Data b) Calculation
c) Placing d) Sorting
45. Reproduction refers to
(a) Making Data Readable (b) Making Data Clear
(c) Making Data Presentable (d) Making Data Duplicate
46. Which one is not a file type with reference to usage point of view
(a) Transaction File (b) Master File
(c) Program File (d) Backup File
[Ch#1] Data Basics 32 Computer Science Part-II
47. Which one is a file type with reference to usage point of view
(a) Transaction File (b) Data File
(c) Program File (d) Sequential File
48.  is also called data set:
(a) Field (b) Record
(c) File (d) All
49.  contains only one type of data:
(a) Field (b) Record
(c) File (d) Database
50.  files contains information that remains constant over a long period of
time:
(a) Master file (b) Backup file
(c) Transaction file (d) None of these
51.  files type is used to update data in master file:
(a) Backup file (b) Transaction file
(c) Sequential file (d) Data file
52. A file that is used to keep a copy of important data is called:
(a) Master file (b) Transaction file
(c) Backup file (d) Data file
53. The data can be recovered in case of loss by using?
(a) Master file (b) Program file
(c) Backup file (d) Data file
54.  file type is executable file and contains the set of program’s
instructions:
(a) Backup file (b) Program file
(c) Master file (d) Data file
55.  may be a temporary file:
(a) Master file (b) Transaction file
(c) Backup file (d) None of these
[Ch#1] Data Basics 33 Computer Science Part-II
56. Which file contains the data prior to the stage of processing
(a) Data File (b) Transaction File
(c) Program File (d) Backup File
57. The Latest update files are
(a) Data File (b) Transaction File
(c) Master File (d) Backup File
58. Program files contain
(a) Data about program (b) Instructions
(c) Data about Transactions (d) Records
59. In which type of file key fields are stored separately
(a) Program File (b) Indexed Sequential File
(c) Sequential File (d) Random File
60. Hardware refers to the
(a) Database Components (b) Logical Components
(c) Data Components (d) Physical Components
61. Collection of programs used to manage database
(a) Database System (b) DBMS
(c) Data System (d) Database Manager
62. Which one is not advanced capability of DBMS
(a) Online (b) Ad-hoc Reporting
(c) Backup / Recover (d) Speed
63. The extension of a file created in Notepad is:
(a) .doc (b) .txt
(c) .exe (d) .pad
[Ch#1] Data Basics 34 Computer Science Part-II
64. Database file has a file extension:
(a) .xls (b) .txt
(c) .mdb (d) .mpg
65. Which of the following file extensions represents the image file?
(a) .gif (b) .jpg
(c) .bmp (d) All of these
66. The techniques used to write and retrieve data to and from the storage devices are
called:
(a) Storage Methods (b) Access Methods
(c) None of these (d) Index Methods
67. Which files organization uses the magnetic storage media?
(a) Direct (b) Random
(c) Indexed Sequential (d) Sequential
68.  files requires largest processing time:
(a) Sequential file (b) Random file
(c) Indexed sequential files (d) Direct access file
69. Multiple copies of the same data is referred to as:
(a) Data integrity (b) Data Redundancy
(c) Data inconsistency (d) Both (a) and (b)
70. Which one is not the feature of DBMS
(a) Utilities (b) Storage
(c) Data Dictionary (d) Report Generator
71. Which one is not an SQL statement
(a) CREATE (b) INSERT
(c) GET (d) SELECT
72.  problems occurs in traditional file system:
(a) Data Redundancy (b) Data inconsistency
(c) Data security (d) All of these
73. A collection of logically related data is called.
(a) Record (b) Data file
(c) Database (d) None of these
[Ch#1] Data Basics 35 Computer Science Part-II
74. A collection of data that include name, address, NIC number, phone number etc.
of an employee represents:
(a) Data base (b) Field
(c) Data set (d) Record
75.  refers to the correctness and consistency of data:
(a) Data independence (b) Data integration
(c) Data integrity (d) Data model
76.  identifies the data items to be stored into database and the relationships
between them:
(a) Data independence (b) Data integration
(c) Data integrity (d) Data model
77.  represents a collection of concepts that are used to describe the
structure of a databas:
(a) Data warehouse (b) Data model
(c) Data structure (d) Data type
78.  data base models has the shape like an organization chart:
(a) Network Model (b) Relational Model
(c) Hierarchical Model (d) None of these
79. The term “inverted tree” is used in:
(a) Network Model (b) Relational Model
(c) Hierarchical Model (d) None of these
80. In  data base models, a complex diagram may be used to represent the
structure of database:
(a) Network Model (b) Relational Model
(c) Hierarchical Model (d) None the these
81.  data base models is commonly used today:
(a) Network Model (b) Relational Model
(c) Hierarchical Model (d) None of these
82.  database models has no physical connections between entities:
(a) Network Model (b) Relational Model
(c) Hierarchical Model (d) None of these
[Ch#1] Data Basics 36 Computer Science Part-II
83.  is the component of DBMS:
(a) Data (b) Hardware
(c) Software (d) All of these
84.  is related to personnel, a component of DBMS:
(a) Application Programmer (b) End users
(c) Database Administrator (d) All of these
85.  contains data definitions used in the database:
(a) Utilities (b) Data Dictionary
(c) Database integrity (d) All of these
86. The printed or onscreen display of data or information in the database is called:
(a) Entity (b) Report
(c) Query (d) Screen
87. The type of files from functional point of view may include:
(a) Program file (b) Backup file
(c) Transaction file (d) None of these
88. The type of files from storage point of view may include:
(a) Transaction file (b) Sequential file
(c) Backup file (d) Data file
89. Video file has a file extension:
(a) .avi (b) .wav
(c) .mpg (d) both (a) & (c)
90. Audio file has a file extension:
(a) .avi (b) .wav
(c) .mid (d) both (b) & (c)
91. .doc represents:
(a) File name (b) File extension
(c) File type (d) None of these
92. The objectives of database may include:
(a) data integration (b) data independence
(c) data integrity (d) All of these
[Ch#1] Data Basics 37 Computer Science Part-II
93. The objectives of database system or DBMS may include:
(a) Database integrity (b) Availability
(c) Evolveability (d) All of these
94.  is handled by database system or DBMS:
(a) Data security (b) Data independence
(c) Data integrity (d) All of these
95.  is the feature of DBMS:
(a) Data dictionary (b) Backup & Recovery
(c) Query language (d) All of these
96. DBMS stands for
(a) Databasics Methodology System (b) Database Managerial System
(c) Database Management System (d) None of Above
Q3. Write T for true and F for false statement
1. Data can only be processed through computers. (F)
2. The traditional file system approach has many advantages over DBMS. (F)
3. Data dictionary is used to view the meanings of database terminology. (F)
4. Master file is the latest updated file which never becomes empty, ever since it is
created. (T)
5. SQL is used to retrieve information from the database based on certain criteria.(T)
6. The Network Data Model is more popular and widely used than Relational Data
Model. (F)
7. Indexed sequential files can be processed sequentially as well as randomly. (T)
8. Backup files store data prior to its processing. (F)
9. Microsoft ACCESS is a relational database management system. (T)
10. A report generator is used to produce a printed document from the database. (T)
[Ch#2] Basic Concepts and Terminology 50 Computer Science Part-II

Q1. Fill in the blanks


1. A(n) table is a two dimensional array containing descriptive information about an
entity.
2. A(n) entity is any thing about which the information is kept in the database.
3. In a table the order of rows and columns is insignificant.
4. In a relation, the attribute or a combination of attributes that uniquely identifies a
record is called primary key.
5. A(n) attribute describes the characteristics of an entity.
6. A(n) foreign key is an attribute in a table whose values must match a primary key
in another table.
7. A(n) DBA is responsible for the design, implementation, operation, management
and maintenance of the database.
8. A(n) composite key consists of two or more attributes.
9. A(n) view is the dynamic result of one or more relational operations on the base
relations to produce another relation.
10. The data refers to raw facts and figures.
Q2. Select the correct option
1. Insert command is used to insert.
(a) a new table (b) a new record
(c) a view (d) dependencies
2. The foreign key is found in
(a) parent table (b) dependant table
(c) pivot table (d) index table
3. Anything in the real world that has a set of different attributes or properties is
called:
(a) Database (b) Data set
(c) Entity (d) Data
4.  represents an entity:
(a) Car (b) Student
(c) House (d) All of these
5. A table is also known as:
(a) Two-dimensional array (b) Relation
(c) Both (a) and (b) (d) None
[Ch#2] Basic Concepts and Terminology 51 Computer Science Part-II
6. A table is also known as
(a) Multiple arrays (b) Relation
(c) A file (d) None of these
7. A tuple in a table is also known as
(a) Occurrence (b) Attribute
(c) Relation (d) Record
8. The columns of a relation correspond to:
(a) Table (b) Cell
(c) Fields (d) Records
9. The rows of a table or relation are known as:
(a) Tuples (b) Occurrences
(c) Both (a) and (b) (d) None
10. The column of a relation is known as
(a) Attribute (b) Tuple
(c) Relation (d) Record
11.  is used to create data view:
(a) Database Manager (b) SQL
(c) Report Generator (d) Utilities
12.  is used to uniquely identify records of a relation:
(a) Secondary key (b) Foreign key
(c) Sort key (d) Primary key
13. A table must have:
(a) Primary key (b) Secondary key
(c) Composite key (d) Sort key
14. A key that consists of two or more than two attributes of a table is called
(a) Composite Key (b) Foreign Key
(c) Primary Key (d) Sort Key
15. An attribute is also known as:
(a) Relation (b) Row
(c) Field (d) Tuple
16.  is known as control key:
(a) Sort key (b) Primary key
(c) Candidate key (d) Composite key
[Ch#2] Basic Concepts and Terminology 52 Computer Science Part-II
17. SQL is used for
(a) Data manipulation (b) Data definition
(c) Data Deletion (d) All of the above
18. Which of the following is responsible for designing the database system.
(a) Data Administrator (b) End User
(c) Database Administrator (d) Database Manager
19.  serves as a bridge between end users and database administrator:
(a) Data Administrator (b) System Analyst
(c) Application Programmer (d) None
20.  is responsible for designing, coordinating and monitoring the database
system:
(a) Data Administrator (b) End-user
(c) Database Administrator (d) Database manager
21. The concept of database evolved from old
(a) Computers
(b) Software
(c) Traditional File Management system
(d) Systems
22. CREATE TABLE command is used to create a:
(a) Table (b) View
(c) Report (d) Query
23. All the data stored on the hard disk as a combination of
(a) Records (b) Fields
(c) Words (d) 0’s and 1’s
24. Field is another name of
(a) Records (b) Data
(c) Column (d) Table
25. A person, place, event or anything about which data is collected and stored in a
database is called:
(a) Relation (b) Entity
(c) Attribute (d) Record
26. How many primary keys can a relation have?
(a) At least two (b) Only one
(c) No limit (d) None
27. Another name for file is
(a) Collection of Records (b) Instance
(c) Dataset (d) Tuple
[Ch#2] Basic Concepts and Terminology 53 Computer Science Part-II
28. An attribute of a relation of a database that serves as a primary key of another
relation in the same database is called:
(a) Foreign key (b) Candidate key
(c) Control key (d) Alternate key
29. In the Relation ___________ is insignificant
(a) Name of Relation (b) Order of Rows
(c) No of Records (d) Size of Relation
30. Atomicity refers to the
(a) Individual Value in a Cell (b) Individual Value in a Row
(c) Individual Value in a Table (d) Individual Value in a Tuple
31. ______ are created to keep the data safe and secure from un authorized and illegal users
(a) Security (b) Tables
(c) Locks (d) Views
32. To create view ________ statement is also used
(a) Select (b) Form
(c) Enable (d) Visualize
33. The attribute or a combination of attributes used to uniquely identify a row in a
table.
(a) Foreign Key (b) Sort Key
(c) Primary Key (d) Data Key
34. A non unique field is called
(a) Primary key (b) Candidate Key
(c) Alternate Key (d) Secondary Key
35. In the presence of more than one unique fields, one is primary and other one is called
(a) Candidate Key (b) Primary Key
(c) Enable (d) Secondary Key
[Ch#2] Basic Concepts and Terminology 54 Computer Science Part-II
36. Another name for composite key is
(a) Primary Key (b) Control Key
(c) Concatenate Key (d) Sort Key
37. To physically sequence the stored data __________ key is used
(a) Primary Key (b) Control Key
(c) Candidate Key (d) Composite Key
38. A person who is responsible for the organization of entire data of an organization
(a) DBA (b) DA
(c) Administrator (d) System Administrator
39. A person who is responsible for the security and maintenance of database
(a) System Administrator (b) DBA
(c) DA (d) Administrator
40. View is stored in the
(a) Table (b) Row
(c) Database (d) None of Above
Q3. Write T for true and F for false statement
1. The view is not stored in database. (T)
2. Two tables can not have the same name in the database. (T)
3. Index makes the searching of a record faster. (T)
4. Secondary Key must be unique. (F)
5. Te primary key can not work as a sort key. (F)
6. The DBA is responsible for maintaining the database. (T)
7. A file is a collection of related fields. (F)
8. DBMS provide more security to protect data than traditional file management
systems. (T)
9. DBMS is a software used to train database administrator. (F)
10. A relation is also termed as a tuple in relational database. (F)
[Ch#3] Database Design Process 72 Computer Science Part-II

Q1. Fill in the blanks


1. During requirement analysis phase, the project requirements are gathered and
identified.
2. DFD stands for Data Flow Diagram.
3. The process of identifying data objects and relationship between them is called
Data Modeling.
4. The number of occurrences of participating entities in a relationship is determined
by the Cardinality ratio.
5. Modality determines whether the participation of an entity in a relationship is
Mandatory or optional
6. ERD stands for Entity Relationship Diagram.
7. In ERD model, a(n) Entity is represented by a rectangular box.
8. In Centralized database systems, all the data is stored at a single side.
9. In Replicated database multiple copies of the same data are stored at different
sites on the network.
10. In distributed databases, the data is Distributed among various sites.
Q2. Select the correct option
1. Which of the following keys does not hold uniqueness property
(a) Candidate key (b) foreign key
(c) Primary key (d) secondary key
2. An entity related to itself in an ERD model refers to
(a) recursive relationship (b) one-to-many relationship
(c) many-to-many relationship (d) one-to-one relationship
3.  is called the preliminary investigation of the required database:
(a) Project planning (b) Feasibility study
(c) Requirement Analysis (d) Data Analysis
4. In  activities, the possible inputs for the database are collected:
(a) Project planning (b) Feasibility study
(c) Requirement Analysis (d) Data Analysis
5. In  activities, the cost factors are taken into consideration:
(a) Project planning (b) Feasibility study
(c) Requirement Analysis (d) Data Analysis
[Ch#3] Database Design Process 73 Computer Science Part-II
6. Database development process involve mapping of conceptual data model into
(a) object oriented data model (b) network data model
(c) implementation model (d) Hierarchical data model
7. In ERD model, the relationship between two entities is represented by a
(a) diamond symbol (b) rectangular box
(c) oval symbol (d) line
8.  tools in involved to the Data Analysis:
(a) Data Flow Diagram (b) Decision Table
(c) Decision Tree (d) All of these
9. The process to identify the data objects and the relationships between them is:
(a) Data Modeling (b) Data Flow Diagram
(c) Data table (d) None the these
10. The relationship between the entities is represented graphically by using:
(a) E-R Diagram (b) Data Flow Diagram
(c) Flowcharts (d) Decision Tables
11. In hybrid distribution which kind of fragments are stored at only one site
(a) critical fragments (b) non-critical fragments
(c) critical and non-critical fragments
(d) only large fragments
12. What indicates the connection between entities
(a) Relationship (b) Attributes
(c) Occurences (d) Data
13.  is the ingredient of data modeling:
(a) Objects (b) Attributes
(c) Relationships (d) All of these
14. In E-R diagram, a rectangular box is used to represent a(n):
(a) Entity (b) Attribute
(c) Relationship (d) None of these
15. In E-R diagram, an oval shape is used to represent a(n):
(a) Entity (b) Attribute
(c) Relationship (d) None of these
16. In E-R diagram, a diamond shape is used to represent a(n):
(a) Entity (b) Attribute
(c) Relationship (d) None of these
[Ch#3] Database Design Process 74 Computer Science Part-II
17. A technique for physically arranging the records of a file on secondary storage
device is called
(a) Indexes (b) Integrity Constraints
(c) File Organization (d) None of above
18. An index may be created on
(a) Primary Key (b) Secondary Key
(c) Foreign Key (d) All of above
19.  represents entity:
(a) Student (b) Teacher
(c) Train (d) All of these
20.  is not related to an entity:
(a) Person (b) Concept
(c) Action (d) Object
21.  is used to associate entities with one another:
(a) Attributes (b) Relationship
(c) Occurrences (d) Identifier
22.  is a type of relationship:
(a) One-to-One (b) One-to-Many
(c) Many-to-Many (d) All of these
23.  is an example of one-to-one relationship:
(a) Country – Capital (b) Mother – Daughter
(c) Teacher – Student (d) Both (a) & (c)
24. The relationship between entities is represented graphically by using.
(a) E-R Diagram (b) Context Level Diagrams
(c) Decision Table (d) Data Flow Diagram
25. Data is stored at single site while following
(a) Centralized Strategy (b) Distributed Strategy
(c) Hybrid Strategy (d) Partitioned Strategy
26. Which Involves the area identification and selection
(a) Feasibility Study (b) Initial Study
(c) Feasibility Analysis (d) Initial Analysis
27. In which phase proper market analysis is also worked out
(a) Initial Analysis (b) Initial Study
(c) Feasibility Analysis (d) Feasibility Study
[Ch#3] Database Design Process 75 Computer Science Part-II
28.  is an example of one-to-many relationship:
(a) Country – Capital (b) Mother – Daughter
(c) Father – Son (d) Both (b) & (c)
29.  defines the nature of the relationship:
(a) Cardinality (b) Modality
(c) Both (a) and (b) (d) None of these
30. The optional relationship is represented by:
(a) O (b) |
(c) |< (d) None of these
31.  is related of modality:
(a) Optional (b) Mandatory
(c) Cardinality (d) Both (a) & (b)
32. What is the major objective of database design?
(a) To draw E-R diagrams.
(b) To map the conceptual data model to an implementation model.
(c) To design the database model.
(d) None of these
33. Possible inputs and the required functionality output of system is determined during
(a) Feasibility Analysis (b) Requirement Analysis
(c) Project Planning (d) Analysis
34. All the hardware costs are considered during
(a) Project Planning (b) Requirement Analysis
(c) Feasibility Analysis (d) Analysis
35. All the relationships are
(a) Uni-directional (b) Bi-directional
(c) Tri-directional (d) All of Above
36. Father & children is an example of
(a) One to One (b) Many to Many
(c) One to Many (d) None of Above
37.  activities is performed in logical design process:
(a) Represent Entities (b) Represent relationships
(c) Normalize the relations (d) All
38. Merging the relations is also called:
(a) View data model (b) View integration
[Ch#3] Database Design Process 76 Computer Science Part-II
(c) View Relation (d) None of these
39. Organizing the database on secondary storage is related to:
(a) Logical design (b) Physical design
(c) Implementation (d) Analysis
40.  is not component of physical database design:
(a) Data volume & usage Analysis
(b) File organization
(c) Normalization
(d) Integrity constraints
41. In  components of physical database design, the size of database is
estimated:
(a) Data volume & usage Analysis
(b) Data Distribution Strategy
(c) Indexes
(d) Integrity constraints
42.  components of physical database design is related to the networking
through which the data of database is shared among different users:
(a) Data volume & usage Analysis
(b) Data Distribution Strategy
(c) Indexes
(d) Integrity constraints
43.  is the basic data distribution strategy:
(a) Centralized (b) Partitioned
(c) Replicated (d) Hybrid
(e) All
44. In ERD there are
(a) Data Objects (b) Relationships
(c) Both a and b (d) None of Above
45. The primary objective of ERD is to represent
(a) Data Objects (b) Cardinality & Modality
(c) Association (d) All of Above
46. The implementation model of database design is derived from
(a) Relational Model (b) Conceptual Model
[Ch#3] Database Design Process 77 Computer Science Part-II
(c) User Model (d) All of Above
47. Database users require _____________ information
(a) Complete (b) Up to Date
(c) Fast (d) All of Above
48. Which one is not a data distribution strategy
(a) Centralized (b) Balanced
(c) Replicated (d) Partitioned
49. In _______________database is divided into fragments
(a) Partitioned (b) Hybrid
(c) Replicated (d) Centralized
50.  is not a basic data distribution strategy:
(a) Centralized (b) Partitioned
(c) Hybrid (d) Duplicated
51. In which strategy full copy of database is assigned to more than one sites in the network
(a) Partitioned (b) Balanced
(c) Replicated (d) Centralized
52. In which strategy there is a problem of update
(a) Partitioned (b) Balanced
(c) Replicated (d) Centralized
53. In _______________database is divided critical and non critical fragments
(a) Partitioned (b) Hybrid
(c) Replicated (d) Balanced
54. Critical fragments are stored at ____site(s)
(a) 1 (b) 2
(c) 3 (d) Multiple
55. In database correctness and consistency refers to the
(a) Constraints (b) Database Constraints
(c) Integrity Constraints (d) None of Above
56.  components of physical database design refers to the correctness and
consistency of data:
(a) Indexes (b) Integrity constraints
(c) File organization (d) Data distribution strategy
57.  components of physical database design is another form of data
protection:
(a) Indexes (b) Integrity constraints
[Ch#3] Database Design Process 78 Computer Science Part-II
(c) File organization (d) Data Distribution strategy
58. In hybrid distribution which kind of fragments is stored at only one site:
(a) Critical fragments
(b) Non-Critical fragments
(c) Critical and non-critical fragment
(d) Only large fragments
Q3. Write T for true and F for false statement
1. In one-to-one relationship only one instance of each entity can participate in the
relationship. (T)
2. The optional modality is represented by 1. (F)
3. One-to-many is a uni-directional relationship. (F)
4. In ERD model, a condition is mentioned in a diamond symbol. (T)
5. ERD is a physical data model. (F)
6. In hybrid distribution the database is portioned in critical and non-critical
fragments. (T)
7. In distributed databases, the consistency refers to availability of same data at all
sites of the network. (T)
8. Indexing maximizes the time required to search a piece of information from a
database. (F)
9. Analysis is less important activity than coding, so minimum time should be spent
over analyzing the system. (F)
10. Relationship defines the logical connection between entities. (T)
[Ch#4] Data Integrity & Normalization 91 Computer Science Part-II

Q1. Fill in the blanks


1. Entity integrity constrains states that the primary key can not be null.
2. Foreign key must refer to the primary key in another table or it must be null.
3. Normalization is the process of converting complex structures into simple and
stable structures.
4. A(n) functional dependency is a partial relationship between attributes of an
entity.
5. During the first normal form repeating groups are removed.
6. To be in 2NF, a relation must be in 1NF.
7. In 3NF, no transitive dependency exists.
8. A(n) partial functional dependency exists when one or more non-key attributes
are functionally dependant on part of the primary key.
9. When a new record is added in a relation, it may cause insertion anomaly.
10. Referential integrity is a constraint on foreign key value.
Q2. Select the correct option
1. In 3NF, which form of dependency is removed?
(a) Functional (b) non-functional
(c) associative (d) transitive
2. How many types of data integrity are there?
(a) 2 (b) 3
(c) 4 (d) 5
3. The ________ constraint states that in a relation no primary key value can have a
null value.
(a) Referential integrity (b) Entity integrity
(c) Data integrity (d) All of these
4. In 3NF, a non-key attribute must not depend on a(n)
(a) non-key attribute (b) key attribute
(c) composite key (d) sort key
5. Different attributes in two different tables having same name are referred to as
(a) synonym (b) homonym
[Ch#4] Data Integrity & Normalization 92 Computer Science Part-II
(c) acronym (d) mutually exclusive
6. Referential integrity is applied on
(a) Primary Key (b) Candidate Key
(c) Foreign key (d) Composite key
7.  problems occurs when two different names are used for the same
information?
(a) Homonyms (b) Synonyms
(c) Redundant information (d) Mutually exclusive data
8.  problems occurs when same name is used for two different attributes:
(a) Homonyms (b) Synonyms
(c) Redundant information (d) Mutually Exclusive data
9.  problems occurs when same information is stored in two different ways:
(a) Homonyms (b) Synonyms
(c) Redundant Information (d) Mutually Exclusive data
10. The process of converting complex data structure into simple and stable data
structure is called:
(a) Synonyms (b) Homonym
(c) Normalization (d) Redundancy
11. A functional dependency between two or more non-key attributes in a relation is
called
(a) Redundancy (b) Consistency
(c) Transitive Dependency (d) None of above
12. Data integrity is another form of data
(a) Data Feasibility (b) Data Accessibility
(c) Data modeling (d) Data Protection
13. Integrity is concerned with the _________ of Data
(a) Reliability (b) Quality
(c) Feasibility (d) Accessibility
14. A foreign key constraint is also called
(a) Referential Integrity (b) Integrity
(c) Entity Integrity (d) Field Integrity
15. In which of the following normal forms, any repeating group from the table is
removed?
(a) 1NF (b) 2NF
[Ch#4] Data Integrity & Normalization 93 Computer Science Part-II
(c) 3NF (d) None
16. A relation is in second normal form if and only if:
(a) It is in 1NF and all the non-key attributes are fully functionally
dependent upon the key attribute.
(b) It is in the 1NF and no transitive dependency exists
(c) It is in the 1NF and every attribute is single valued for each tuple.
(d) All of these
17. If a relation is in 1NF and the key consists of a single attributes then the relation is
called.
(a) 3NF (b) 2NF
(c) Both (a) & (b) (d) None
18. If the value of a non-key attribute can be obtained simply by knowing the values
of another non-key attribute, the relation is not in:
(a) 1NF (b) 2NF
(c) 3NF (d) None
19. A process in which it is being ensured that attributes are stored from where they belong
(a) Normalization (b) Simplification
(c) Structure Constraint (d) Field Constraints
20. A process of analyzing the dependencies of attributes with in entities is called
(a) Normalization (b) Simplification
(c) Structure Constraint (d) Field Constraints
21. The attribute on left hand side of arrow is called
(a) Entity (b) Determinant
(c) Determined (d) Attribute
22. Which form of dependency is removed for 2NF?
(a) Functional (b) Transitive
(c) Associative (d) Partial
23.  anomalies arise due to transitive dependency:
(a) Insertion (b) Deletion
(c) Modification (d) All of these
24. The objective of normalization is to:
(a) Increase data redundancy (b) Increase number of relations
[Ch#4] Data Integrity & Normalization 94 Computer Science Part-II
(c) Get stable data structure (d) All of these
Q3. Write T for true and F for false statement
1. Normalization is the process of converting complex data structures into simple
data structures. (T)
2. A relation is decomposed to convert into from 1NF to 2NF. (T)
3. The primary key cannot be a composite key. (F)
4. In 2NF, every non-key attribute must depend on the key attribute. (T)
5. A relationship involving three relations is known as a ternary relationship. (T)
6. A database anomaly leads the database to an inconsistent state. (T)
7. Partial dependencies are removed in 3NF. (T)
8. A relation may have multiple primary keys. (F)
9. In relational database, no relation can exist in isolation. (T)
10. The database is normalized to avoid certain database anomalies. (T)
[Ch#5] Introduction of Microsoft Access 107 Computer Science Part-II

Q1. Fill in the blanks


1. IDE stands for Integrated Development Environment.
2. Database Management System is basically a computerized record keeping system.
3. RDBMS stands for Relational Database Management System.
4. The table object is used to store data in the database.
5. The query object is used to retrieve data from a database.
6. A field with Auto Number data type is automatically incremented by Access each
time a new record is entered.
7. Each row of a table is divided into columns called field.
8. Each row of a table representing a set of information is called tuple.
9. The window that is used to display, enter and edit data on the screen is called
form.
10. A database consists of four major database objects, which are used to store and
retrieve data to and from the database.
Q2. Select the correct option
1. A database consists of various components called the
a) Tool b) Properties
c) Entities d) Objects
2. Which of the following object is used to retrieve data from database and present
in a formatted way?
a) Report b) Form
c) Table d) Query
3.  is the most popular and powerful DBMS:
(a) Ms-word (b) MS-Access
(c) Ms-Excel (d) Ms-PowerPoint
4. MS-Access is a:
(a) Network Database Management system
(b) Object-oriented database Management system.
(c) Relational database Management system
(d) All of these
[Ch#5] Introduction of Microsoft Access 108 Computer Science Part-II
5.  represents of wizard of DBMS:
(a) Database wizard (b) Table wizard
(c) Form wizard (d) All of these
6.  is element MS-Access application window:
(a) Title bar (b) Tool bars
(c) Scrollbars (d) All of these
7. Microsoft Access saves the database with the extension
a) .mdb b) .msdb
c) .madb d) None of them
8. A record is a complete set of __________fields
a) Distinct b) Related
c) Designed d) All of them
9. The actual data of database is stored in:
(a) Tables (b) Queries
(c) Forms (d) Reports
10.  is a collection of related data organized in rows and columns:
(a) Table (b) Query
(c) Report (d) Form
11. In access, the structure of a table is created in ________view
a) design view b) Datasheet View
c) a and b both d) none of them
12. In a table each row represents a
a) Record b) Field
c) Form d) Data saet
13. In a table each column represents a
a) Record b) Field
c) Data set d) Entity
14. A query is a more flexible way of
a) Selecting records from database b) Filtering records from database
c) Sorting records from database d) All of above
15. A step by step procedure to perform a task easily available in a software is called
a) Automation b) Manual
c) Wizard d) None of Above
[Ch#5] Introduction of Microsoft Access 109 Computer Science Part-II
16. Using __________ you can create tables, forms, reports and queries in very short time
a) Menus b) GUI
c) Tools d) Wizard
17. A place where we can see all the tables and their relationship
a) Window b) Dialog Box
c) Relationship Window d) All of Above
18.  is the fundamental property of relational database:
(a) It may contain multiple tables.
(b) It contains only one table.
(c) It contains no tables.
(d) None of these
19. ________ is a statement that extracts specific information database.
(a) Table (b) Query
(c) Report (d) All of these
20. To automate repeated tasks __________are used
a) Instructions b) Wizard
c) Programming d) Macro
21.  is true about query:
(a) User can also change data in the database that fulfills certain criteria.
(b) A query also allows performing calculations of different number fields.
(c) The output of query is also displayed in the form of a table.
(d) All of these
22.  is not true about a query:
(a) A query can be used as source of records for Forms and reports
(b) A query is a stored question or request.
(c) A query allows to access data of only one table of database.
(d) None of these
23.  objects of MS-Access database is used to create user-interface to
perform different operations on database:
(a) Report (b) Query
(c) Macro (d) Form
[Ch#5] Introduction of Microsoft Access 110 Computer Science Part-II
24.  objects is used to display data as well as to change data of database:
(a) Form (b) Report
(c) Both (a) and (b) (d) None
25.  objects is used retrieve data from database and present in a formatted way:
(a) Report (b) Form
(c) Table (d) Query
26. Which is not included in database wizard
a) Template b) Selecting Fields
c) Customizations d) Design Database
27. To create a database in file new database there is a button named
a) Open b) Select
c) Create d) None of Above
28. The bar which identifies the database application you are running in Microsoft Access
a) Tool Bar b) Title Bar
c) Status Bar d) Task Bar
29. In Access, the structure of a table can be created in:
(a) Design View (b) Datasheet View
(c) Both (a) and (b) (d) None
30.  is not a database object:
(a) Form (b) Table
(c) Window (d) Query
31. The bottom most bar in Ms. Access is called
a) Tool Bar b) Title Bar
c) Status Bar d) Menu Bar
32. Which bar is used to see that CAPS button on keyboard is on
a) Tool Bar b) Title Bar
c) Status Bar d) Menu Bar
33. A window that organizes all objects in the database is called
a) Window b) Database Window
c) Dialog d) Database Dialog
34. A database may contain:
(a) Only one table (b) At least two table
(c) Many tables (d) None
[Ch#5] Introduction of Microsoft Access 111 Computer Science Part-II
35. A report may be based on a:
(a) Query (b) Form
(c) Table (d) Both (a) & (c)
36. Microsoft Access database window include __________ buttons
a) Three b) Five
c) Four d) Seven
37. There are _______ major database objects in Ms. Access
a) Two b) Four
c) Three d) Five
38. To database object which actually stores data is called
a) Table b) Form
c) Query d) Repor
Q3. Write T for true and F for false statement:
1. An IDE simplifies the task of creating and using a database. (T)
2. The major objects of database are five. (F)
3. Forms are provided by database management system to generate reports. (F)
4. An integrated development environment is an interface that is used by database
designers and application programmers to create database applications. (T)
5. To view data in an Access table, the table is displayed in design view. (F)
6. RDBMS stand for Relational Database Management System. (T)
7. A request to extract data from a database is called report. (F)
8. Database design plays an important role in achieving the goals of efficiency,
speed and consistency. (T)
9. The table can be displayed in two views in Access. There are design view and
datasheet view. (T)
10. The window in a database IDE that is used to display, enter and edit data on the
screen is called form. (T)
[Ch#6] Table and Query 152 Computer Science Part-II

Q1. Fill in the blanks


1. The primary key is specified in table to avoid duplicate entries of records.
2. In Microsoft Access the data of the table is displayed in datasheet view.
3. In the relational model, table is the basic structure in which data is stored.
4. The ERD is a graphical representation of the structure of a database.
5. The right arrow-head button shows the current record in the table.
6. If the primary key is made up of a group of two or more fields, it is called
composite.
7. Wildcards are special characters that are used in queries to specify the criteria.
8. In Microsoft Access, the output of a query is in the form of a table.
9. A query that involves two tables is called cross table.
10. The wildcard character asterisk (*) is used to specify any number of characters.
11. The memo data type is used when the field is to contain text consisting of about
300 characters.
12. The number of rows in a table of a relational database is called the cardinality of
the table.
13. The number of columns in a table is called the degree of the table.
14. A query that only retrieves and displays data is called select.
15. The wildcard character # is used to specify a single digit.
Q2. Select the correct option
1. The data in table is entered in
a) Design View b) Normal View
c) Datasheet View d) Layout View
2. The rule that a record from a table cannot be deleted if its associated record exists
in a related table is called _____rule
a) Referential Integrity b) Entity-Relationship
c) Normalization d) all of them
3. The fundamental concept of relational database is:
(a) Query (b) Table
(c) Form (d) Record
4. The actual data of database is stored in:
(a) Query (b) Table
(c) Forms (d) Report
[Ch#6] Table and Query 153 Computer Science Part-II
5.  is the object of MS-Access database file:
(a) Queries (b) Tables
(c) Forms (d) All of these
6. In a relational database, a single piece of information is called:
(a) Field (b) Attribute
(c) Entity (d) Both (a) & (b)
7. The number of fields in a relation or table is called:
(a) Degree of relation (b) Cardinality of relation
(c) State of relation (d) None
8. Which of the following buttons of Find and Replace dialog box is clicked to start
he search process?
a) Find b) Find Next
c) Search d) Next
9. As in design view, you can move from field to field in the table window in
datasheet view using ________button.
a) Tab b) Esc
c) Enter d) Spacebar
10. The number of records (or row) in a table or relation is called:
(a) Degree of relation (b) Cardinality of relation
(c) State of relation (d) None
11. How may table view are available in MS-Access?
(a) 1 (b) 2
(c) 3 (d) 4
12. The data in table is entered in:
(a) Design View (b) Normal View
(c) Datasheet View (d) Layout View
13. The structure of table is designed in:
(a) Design View (b) Normal View
(c) Datasheet View (d) Layout View
14.  views can be used to add, edit, and delete records to and from the table:
(a) Design View (b) Record View
(c) Datasheet View (d) Edit View
[Ch#6] Table and Query 154 Computer Science Part-II
15. The relationship between countries and their capitals is an example of
________relationships.
a) one-to-one b) one-to-many
c) many-to-many d) none of them
16.  menus in MS-Access contains commands that can be used to switch
between table views?
(a) File (b) View
(c) Edit (d) Tool
17. The maximum length of text type field is:
(a) 50 Characters (b) 250 characters
(c) 155 characters (d) 255 characters
18.  is not an example of data type in MS-Access:
(a) Memo (b) Menu
(c) Text (d) Currency
19.  is the default data type in MS-Access:
(a) Memo (b) AutoNumber
(c) Text (d) None of these
20.  is the default field size of Text data type in MS-Access:
(a) 100 (b) 50
(c) 255 (d) 150
21. In memo type field, more than ______ characters can be stored.
(a) 64 (b) 640
(c) 6400 (d) 64000
22. The structure of a table can be modified in
a) Datasheet View b) Normal Layout
c) Design View d) None of above
23. The maximum length of text type field is
a) 16 Characters b) 255 characters
c) 64 Characters d) 32 Characters
24.  type of fields cannot be used as key field:
(a) Memo (b) AutoNumber
(c) Text (d) Number
25.  type of fields is used to store the URL address of website:
(a) Text (b) Hyper Link
(c) OLE Object (d) Memo
[Ch#6] Table and Query 155 Computer Science Part-II
26.  can be used to define a field that can store picture, chart, or other
graphic object:
(a) Text (b) Hyper Link
(c) OLE Object (d) Memo
27.  can be used to define a field that can create a sequence of number
automatically:
(a) Currency (b) AutoNumber
(c) Number (d) Memo
28.  specifies the Field property:
(a) Default Value (b) Input Mask
(c) Field Size (d) All
29.  table views, Field properties are shown:
(a) Design View (b) Form
(c) Datasheet View (d) Report
30. Which field is used to store URL address
a) Memo b) Hyperlink
c) Text d) OLE object
31. Which of the following type of queries is used to make changes in database?
a) Parameter Query b) Action Query
c) Select Query d) Crosstab Query
32.  field types can be indexed:
(a) Memo (b) Hyper Link
(c) OLE Object (d) Number
33. The maximum length of a field name in MS-Access is _____ characters.
(a) 64 (b) 640
(c) 6400 (d) 64000
34. To find a four-characters name that starts with H, the criteria is specified as:
(a) H*4 (b) H?4
(c) H??? (d) H###
35.  manus contains Find and Replace commands:
(a) File (b) View
(c) Edit (d) Tool
36. For which data user need not to enter data for that field
a) Number b) Auto Number
c) Automatic Number d) Auto
[Ch#6] Table and Query 156 Computer Science Part-II
37. OLE stands for
a) Object Linking and Embedding b) Object Like Embedding
c) Optional Link Encoding d) None of Above
38. A ___________ will link to a website or another location in the database
a) Link b) Network
c) Hyperlink d) HTTP
39.  buttons of Find and Replace dialog box is clicked to start the search
process:
(a) Find (b) Find Next
(c) Search (d) Next
40. In Design view, you can move from field to field in the Table window in
Datasheet view using ______ button:
(a) Tab (b) Esc
(c) Enter (d) Spacebar
41. An association established between common fields in two tables is called:
(a) Entity (b) Entity-Relationship Model
(c) Relationship (d) Integrity
42. How many types of relationship are there?
(a) 2 (b) 3
(c) 4 (d) 5
43. Arranging data or records of a table in a specific order i.e, in alphabetical or
numeric order is called:
(a) Data sorting (b) Data Filtering
(c) Data querying (d) All
44.  is wildcard character:
(a) > (b) <
(c) + (d) *
45. The optional information while creating a table in design view is
a) Field Data Type b) Description
c) Field Size d) Field Name
46. A value that is set automatically for a field if not value is given by the user is
called
a) Automatic Value b) Value
c) Natural Value d) Default Value
[Ch#6] Table and Query 157 Computer Science Part-II
47. _________controls the value of a record and sets it in a specific format
a) Field Validation Rules b) Data Format
c) Input Mask d) Indexes
48. ________ specify criteria for the data entered in the worksheet
a) Field Validation Rules b) Data Format
c) Input Mask d) Indexes
49. _________allow Access to query and sort records faster
a) Key b) Primary Key
c) Index d) All of Above
50.  is wildcard character:
(a) ? (b) *
(c) ! (d) Both a and b
51. The resulting collection of records is called:
(a) Report (b) Query
(c) Dynaset (d) Form
52.  queries is used to perform calculations on the data of numeric fields:
(a) Select Query (b) Action Query
(c) Parameter Query (d) Crosstab Query
53.  is not an example action query:
(a) Select (b) Delete
(c) Parameter (d) Convert
54.  query is used to join two tables:
(a) Select (b) Delete
(c) Parameter (d) Crosstab
55.  query displays a dialog box to get information from user:
(a) Select (b) Delete
(c) Parameter (d) Crosstab
56. Which menu is used to sort data in Microsoft Access
a) Tools b) Data
c) Records d) Query
[Ch#6] Table and Query 158 Computer Science Part-II
57. Which sign is used for not equal to in Microsoft Access Filter
a) != b) Not =
c) Not Equal To d) <>
58. The filtered contents of a filter in Microsoft Access can be saved as
a) File b) Table
c) Sheet d) Query
59. Criteria to find a word which starts with z and ends with c but can have any
number of characters
a) z?c b) z&c
c) z#c d) z*c
60. The __________ is specified in a table to avoid duplicate entries of records
a) Key b) Field
c) Primary Key d) All of Above
Q3. Write T for true and F for false statement
1. If each entity in B and each entity I B, there is only one relate entity in A, then the
relationship between the entities is one-to-many. (F)
2. Date/Time data type is used when data such as date of birth or time of day is to be
stored. (T)
3. The primary key is assigned in a table to avoid duplicate entries of records. (T)
4. An append query adds a group of records from one or more tables to the end of
one or more tables. (T)
5. The currency data type cannot be used in calculations. (F)
6. The most commonly used type of query is Scratch Query. (F)
7. A query is used to extract specific information from a database. (T)
8. The wildcard character “?” is used to specify any number of characters. (F)
9. Fields are displayed as check boxes by default on the datasheet. (F)
10. An action query makes changes in specified records of an existing table, or
creates a new table. (T)
[Ch#7] Microsoft Access forms & Reports 194 Computer Science Part-II

Q.1 Fill in the blanks:


1. Forms are used to enter, view, and modify or delete data in database.
2. The easiest and quick way to create a form in Microsoft Access is by using
wizard.
3. Tabular form is used to display multiple records at a time in tabular format.
4. A sub-form is a form, which is displayed within the main form.
5. There are basically four layouts of forms in Microsoft Access.
6. The report object is used only to retrieve data from a database and display it on
the screen or print it on the printer. It cannot be used to edit data in a database.
7. Reports can compare, summarize and subtotal large sets of data.
8. In Microsoft Access, a report can be created in any one of the three layouts. These
layouts are Columnar, Tabular, and Justified.
9. Reports are the finished results of your data input to the database backed through
the forms as front end.
10. The report object is used only to retrieve data from a database and displays it on
the screen or print it on the printer. It cannot be used to edit data in a database.
Q.2 Select the correct option:
1. A form that contains the sub form is called
a) Form b) Main Form
c) Report d) None of them
2. How many basic layouts of forms are here in Microsoft Access.
a) 2 b) 3
c) 4 d) 5
3.  objects is not used to enter data into database:
(a) Reports (b) Tables
(c) Forms (d) None
4. A form is an object of:
(a) Table (b) Database
(c) Report (d) Query
[Ch#7] Microsoft Access forms & Reports 195 Computer Science Part-II
5. Forms are designed for:
(a) Input Data (b) Display Data
(c) Accepting Change (d) All of them
6. The forms are the _______ end of our database in Microsoft Access
a) Back End b) Front End
c) Both a and b d) None of them
7. A ______ auto form displays one record at a time.
a) Tabular b) Columnar
c) Datasheet d) Justified
8. Which of the following is used to retrieve data from one or more tables of
database and to present it to the user in a formatted way.
a) Report b) Form
c) Query d) Table
9. Tables are the ______ of our database in Microsoft Access
a) Front end b) Back end
c) both a and b d) none of above
10. How many are the layouts of Form in MS-Access?
(a) 2 (b) 3
(c) 4 (d) 5
11. Which form layout displays multiple records at a time?
(a) Justified (b) Datasheet
(c) Columnar (d) None
12. Form with in a form is called
a) Sub Form b) Main Form
c) both a and b d) none of above
13. A form with multiple tabs and each tab consisting a page of information
a) Parent Form b) Sub Form
c) Swithboard d) multiple page form
14. The different design elements placed on form are called
a) Components b) Object
c) Controls d) All of Above
15. Which is not an example of a control element placed on the form
a) Text Box b) Text
c) Combo Box d) List Box
[Ch#7] Microsoft Access forms & Reports 196 Computer Science Part-II
16. Each of the following is a form layout except.
(a) Justified (b) Datasheet
(c) Columnar (d) Spreadsheet
17. A Form within another form is called:
(a) Main form (b) Special form
(c) Dialog box (d) Sub form
18. The form which contains the subform is known as:
(a) Main form (b) Special form
(c) Dialog box (d) Child form
19. If there are small finite number of values for a certain field on a form which
object will be suitable
a) Text Box b) Text Area
c) Combo Box d) List Box
20. In addition to navigate records can be used for __________
a) Change Data b) Enter Data
c) Open Form d) None of Above
21. ___________ report spreads the information for a single record over many rows
a) Columnar b) Tabular
c) Datasheet d) Justified
22. ___________ report simply provide a column for each field of the records in rows
under the column header
a) Columnar b) Tabular
c) Datasheet d) Justified
23. A formatting that depends on the control’s value is called
a) Formatting b) Logical Formatting
c) Data Formatting d) Conditional Formatting
24. Report can be printed using _____ menu
a) File b) Edit
c) Print d) Tools
25. A subform can be created using:
(a) Form wizard (b) Subform wizard
[Ch#7] Microsoft Access forms & Reports 197 Computer Science Part-II
(c) Drag and drop method (d) All
26.  control objects is also called Push button:
(a) Radio Button (b) Command Button
(c) Check Box (d) None
27.  is used to display a list of items on the form:
(a) Check Box (b) List Box
(c) Combo Box (d) Both b & c
28.  is used to display options that have values in the form of True/False or
Yes/No:
(a) Check Box (b) Option Button
(c) Combo Box (d) Both a & b
29. A Form that contains multiple tabs and each tab consists of a page of information
is called:
(a) Switchboard (b) Subform
(c) Parent Form (d) Multiple page Form
30. The process of using data of another database in current database without copying
it is called __________
a) Attaching b) Adding
c) Shifting d) Linking
31. To link a database ________ menu is used
a) Add b) File
c) Link d) Tools
32. A form that appears at the start of the application is called
a) Start Form b) Initial Form
c) Switch Board d) First Form
33. Which menu is used to access switchboard manager
a) File b) Edit
c) Switch d) Tools
34.  is used to retrieve data from one or more tables of database and to
present it to the user in a formatted way:
(a) Report (b) Form
[Ch#7] Microsoft Access forms & Reports 198 Computer Science Part-II
(c) Query (d) Table
[Ch#7] Microsoft Access forms & Reports 199 Computer Science Part-II
35. How many are layouts of report?
(a) 2 (b) 3
(c) 4 (d) 5
36. Which type of report can display multiple records on one page?
(a) Tabular (b) Datasheet
(c) columnar (d) Both (a) & (c)
37. To close the switch board automatically which command can be associated with a
button
a) Close b) Exit
c) Stop d) Unload
38.  is not type of report:
(a) Tabular (b) Datasheet
(c) Columnar (d) None
39.  is the main function of a report:
(a) Edit data (b) Delete data
(c) Accept data (d) Displays data
Q.3 Write T for true and F for false statement:
1. A form can enter, edit and retrieve data from only on table at a time. (F)
2. When a form is closed, the records entered in the form are automatically save din
the database. (T)
3. We cannot change any record of a table in a database using a form. (F)
4. A form within another form is known as tabular form. (F)
5. The tabular layout of a form is called datasheet layout. (F)
6. We have not any facility to test a conditional statement in reports. (F)
7. The easiest way to create a report in Microsoft Access is by using the Report
Wizard. (T)
8. The options for layout of report are Columnar, Tabular and Justified. (T)
9. Reports are primarily used to input data easily into database tables. (F)
10. The record navigation buttons at the lower-left corner of a form are used to save
recently edited data in the database. (T)
[Ch#8] Getting Started with C 214 Computer Science Part-II

Q.1 Fill in the Blanks:


1. The set of instructions given to the computer to perform a task is called the
program.
2. ANSI stands for American National Standard Institute.
3. A computer program written in high level language is known as Source code.
4. Loader is a program that places executable file in the memory.
5. In Unstructured programming language the entire logic of the program is
implemented in a single module.
6. Preprocessor directive are commands that give instructions to the C preprocessor.
7. Constant macro is a name that is replaced by a particular constant before program
is sent to the compiler.
8. The Include directive given a program access to a library file.
9. C program is divided into units called Functions.
10. Every statement in a C program terminates with a Semicolon.
11. A language translator for assembly language is called Assembler.
12. A set of rules for writing program in high level language is known as Syntax.
Q.2 Choose the correct option:
1. C is a:
a) High level language b) Low level language
c) Assembly language d) Machine language
2. Turbo C++ can compile:
a) C++ programs only b) C and C++ programs
c) Turbo c programs d) Turbo C++ programs only
3. Debug is the process of:
a) Creating bugs in the program b) Identifying and removing errors.
c) Identifying errors d) Removing errors
4. A set of instruction given to the computer is called:
(a) Hardware (b) Software
(c) Computer language (d) None
5. The computer program is written in:
(a) English language (b) Programming language
[Ch#8] Getting Started with C 215 Computer Science Part-II
(c) Both (a) & (b) (d) None
6. The programming languages that are close to human language are called:
(a) High-level language (b) Low-level language
(c) Medium-level language (d) Machine language
7.  is not a high level language:
(a) C (b) Java
(c) Assembly (d) Fortran
8. The programming language that are very close to machine code are called:
(a) High-level language (b) Low-level language
(c) Medium-level language (d) Machine language
9.  is not a low-level language:
(a) C-language (b) Machine language
(c) Assembly language (d) None
10. The computer understands the instructions only in:
(a) Machine code (b) Assembly code
(c) Symbolic code (d) ACII code
11.  language is known as fundamental computer language:
(a) C (b) Assembly
(c) Machine language (d) Java
12. A program written in ________ language runs directly on the computer.
(a) C (b) Machine
(c) Assembly (d) FORTRAN
13. The symbols used to write instructions in assembly language are called:
(a) Symbolic (b) Binary code
(c) Mnemonics (d) Nemonics
14. C was designed to write programs for:
a) Windows operating system b) Solaris operating system
c) Unix operating system d) OS/2 operating system
15. Preprocessor directives are commands for:
a) Microprocessor b) Language processor
c) C preprocessor d) Loader
16. Which of the following requires no translator to execute the program?
a) C b) C++
[Ch#8] Getting Started with C 216 Computer Science Part-II
c) Machine language d) Assembly language.
17. .exe file is produced by the:
a) linker b) loader
c) compiler d) interpreter
18. The program written in assembly language is translated to the machine code with
the help of translator program called:
(a) Complier (b) Assembler
(c) Interpreter (d) Decoder
19. The instructions written in machine language are in the form of:
(a) ACSII code (b) EBCDIC code
(c) Binary code (d) Instruction code
20.  languages is different for different computers:
(a) C (b) Java
(c) Assembly (d) BASIC
21.  languages requires no translator to execute the program:
(a) C (b) C++
(c) Machine (d) Assembly
22. The translated program into machine code is called:
(a) Source program (b) Object program
(c) System program (d) None
23. The special programs that are used to convert a source code into object code are
called:
(a) Language translator (b) Language processor
(c) Both (a) & (b) (d) Preprocessor
24. C, C++, Java, Basic etc. are examples of:
(a) High-level languages (b) Low-level languages
(c) Medium-level languages (d) None of these
25.  language translator programs is used to translate the C program:
(a) Compiler (b) Interpreter
(c) Assembler (d) None
26.  translator programs is best for debugging the source code:
(a) Compiler (b) Interpreter
[Ch#8] Getting Started with C 217 Computer Science Part-II
(c) Assembler (d) None
27.  languages provided the basis for the development of C:
(a) B (b) C++
(c) Pascal (d) Ada
28. Which of the following key is used to save a file?
a) F2 b) F3
c) F5 d) F9
29. Void occupies how many bytes in memory
a) Zero b) One
c) Two d) Four
30. Which of following is not a high level language
a) JAVA b) FORTRAN
c) COBOL d) Assembly
31. The translated program into machine code is called
a) System Program b) Machine program
c) Program d) Object Program
32. C-language can be used to develop:
(a) System programs (b) Application programs
(c) Games (d) All of these
33. C is a:
(a) High-Level Language (b) Low-Level Language
(c) Assembly Language (d) Machine Language
34. Turbo C++ can compile:
(a) C++ programs only (b) C and C++ programs
(c) Turbo C programs only (d) Turbo C++ programs only
35.  represents the beginning of the actual program:
(a) Header files (b) Preprocessor
(c) Main function (d) # include
36.  signs represents the preprocessor directives:
(a) & (b) $
(c) <> (d) #
37. The extension of the header file is:
(a) .c (b) .doc
[Ch#8] Getting Started with C 218 Computer Science Part-II
(c) .h (d) .cpp
38.  word is used to include the header file:
(a) Define (b) If
(c) Include (d) While
39. The name of header file is written between?
(a) { } (b) <>
(c) [ ] (d) ( )
40.  represents the preprocessor directive:
(a) Void main (void) (b) { }
(c) # include <stdio.h> (d) None
41. The instructions that are given to the compiler before the beginning of the source
code are called:
(a) Preprocessors (b) Preprocessor directives
(c) Mnemonics (d) None
42.  signs is used at the end of statement of C program:
(a) # (b) :
(c) . (d) ;
43.  massages is displayed by C-complier if semicolon is missing at end of
the statement:
(a) Semicolon missing; (b) Statement missing;
(c) Prototype missing; (d) error in program;
44. Which directory of TC contains the header files?
(a) LIB (b) DATA
(c) HEADER (d) INCLUDE
45. Which part of the compiler handles the preprocessor directives?
(a) Supervisor (b) Shell
(c) Processor (d) Preprocessor
46. Which one is used as statement terminator in C language
a) . b) ,
c) ) d) ;
47.  is a correct preprocessor directive:
(a) # include (stdio.h) (b) # include <stdio.h)
[Ch#8] Getting Started with C 219 Computer Science Part-II
(c) # include <stdio.h> (d) # include [stdio.h]
48. The file extension of C source program is:
(a) .obj (b) .exe
(c) .cpp (d) .c
49. In C, the linker creates a file with file extension:
(a) .obj (b) .exe
(c) .cpp (d) .c
50. Preprocessor directives commands for:
(a) Microprocessor (b) Language processor
(c) C-complier (d) Loader
51. The expression in define directive:
(a) Can only be changes at the end of the program
(b) Can not be changed
(c) Can not be changed but can be redefined
(d) Can not be assigned a value
52. The file with extension obj is produced by the:
(a) Linker (b) Loader
(c) Compiler (d) Interpreter
53.  key is used to save a file:
(a) F2 (b) Alt + F2
(c) F5 (d) F9
54. Which of the following language provide the basis for C language?
a) A b) C++
c) B d) Cobol
55.  errors occurs during program execution:
(a) Syntax (b) Logical
(c) Runtime (d) None
56. The errors in the program are called:
(a) Syntax (b) Bugs
(c) Mistakes (d) Debugging
57. _______ is the process of translating source code into machine code is called:
(a) Compiling (b) Executing
[Ch#8] Getting Started with C 220 Computer Science Part-II
(c) Linking (d) Debugging
58. The process of running the program on the computer is called:
(a) Compiling (b) Executing
(c) Linking (d) Debugging
59. C language was developed in _______
a) 1962 b) 1969
c) 1970 d) 1972
60. Programming language B was developed by
a) Ken Ritchie b) Ritchie Thompson
c) Ken Thompson d) None of Above
61. To open a new file in Turbo C editor which menu is used
a) Edit b) Open
c) Tools d) File
62. To get help in turbo c
a) F3 b) F2
c) F1 d) F5
63. To switch between editor and output window
a) Alt + F3 b) Alt + F2
c) Alt + F1 d) Alt + F5
64. To compile a program press
a) F9 b) Alt + F9
c) Ctrl + F9 d) Ctrl + F5
65. The process of linking library files with object code is called:
(a) Compiling (b) Executing
(c) Linking (d) Debugging
66. C language was developed by:
(a) Von Neumann (b) Dennis Ritchie
(c) Charles Babbage (d) John Backus
67. An IDE of Turbo C consists of:
(a) Text Editor (b) Debugger
[Ch#8] Getting Started with C 221 Computer Science Part-II
(c) Linker (d) All of these
[Ch#8] Getting Started with C 222 Computer Science Part-II
68. The file extension of object file of C program is:
(a) .obj (b) .exe
(c) .cpp (d) .c
69. To run a program press
a) F9 b) Alt + F9
c) Ctrl + F9 d) Ctrl + F5
70. TC assigns a default name ______________ to a new file
a) NONAME.C b) NONAME0.CPP
c) NONAME00.C d) NONAME00.CPP
71. Computer cannot under stand
a) Program b) Source Program
c) Object Program d) All of Above
72. Which produces object program from source program
a) Program b) Compiler
c) Debugger d) Computer
73. A lot of ready made functionality available in
a) Source Files b) Library Files
c) Object Files d) None of Above
74. Which program produces object(obj) file
a) Compiler b) Linker
c) Loader d) All of Above
75. The .exe file is created by:
(a) Loader (b) Compiler
(c) Linker (d) Interpreter
76. The basic structure of C program consists of:
(a) Main () function (b) Preprocessor directives
(c) Body of program (d) All
77.  requires no translator program to translate the program into machine
language?
(a) C/C++ (b) Machine
(c) Assembly (d) Basic
[Ch#8] Getting Started with C 223 Computer Science Part-II
78.  can only detect the syntax errors:
(a) Linker (b) Loader
(c) Debugger (d) Compiler
79. The program that modifies the c program prior to its compilation
a) Preprocessor b) Compiler
c) Linker d) Loader
80. A name that is replaced by a particular constant value before the program is sent
to the compiler
a) Micro b) Constant
c) Constant Macro d) Constant Micro
81. The error that is due to some illegal operations in a program is called
a) Run Time Errors b) Syntax Errors
c) Logical Errors d) Mathematical Errors
82. A language which is very close to computer
a) High Level b) Machine Language
c) Assembly Language d) Human Language
83. A language which is very close to humans
a) High Level b) Machine Language
c) Assembly Language d) None of Above
84.  errors cannot be detected by compiler:
(a) Syntax (b) Logical
(c) Runtime (d) Both b & c
85. Spelling errors in the program are example of:
(a) Syntax errors (b) Logical errors
(c) Runtime errors (d) None
86. Division by zero is an examples of:
(a) Syntax errors (b) Logical errors
(c) Runtime errors (d) None
87.  is not high-level language:
(a) C (b) Java
(c) Assembly (d) BASIC
88.  is the low-level language:
(a) C++ (b) Assembly
(c) Machine (d) Both b & c
[Ch#8] Getting Started with C 224 Computer Science Part-II
89. The compiler can detect ________ errors at the time of compilation
a) Run Time Errors b) Syntax Errors
c) Logical Errors d) Mathematical Errors
90. Which language is hardware dependent
a) High Level b) Low Level
c) Human Language d) All of Above
91.  language is suitable for developing business application:
(a) C++ (b) Assembly
(c) Basic (d) COBOL
92.  is a type of language translator:
(a) Assembler (b) Compiler
(c) Interpreter (d) All of these
93.  translators translates the source code into object code as a whole:
(a) Assembler (b) Compiler
(c) Interpreter (d) None
94.  translators translates the source code into object code statement-by-
statement:
(a) Assembler (b) Compiler
(c) Interpreter (d) None
Q.3 Write T for True, F for False statement:
1. The C programming language was developed by Dennis Ritchie in 1972. (T)
2. C was designed from the earliest programming language named B. (T)
3. The B was developed by Ken Thomson in 1980. (F)
4. The shortcut key for compiling a program in Turbo C++ IDE is Alt+F9. (T)
5. The compiler produces the source file from an object file. (F)
6. The linker is a program that combines the object program with additional
(T)
files.
7. The shortcut key for executing the C program is Alt+F5. (F)
8. In structured programming, the entire program is divided into smaller
(T)
modules.
9. The value of a constant can be changed during the program execution. (F)
10. High level language provides machine independence. (T)
[Ch#9] Elements of C 259 Computer Science Part-II

Q.1 Fill in the blanks:


1. The first character of a variable name must be an alphabet or underscore.
2. Binary operators operates on two operands.
3. Named memory cells which are used to store programmer’s input and output are
called variables.
4. The maximum length of a character constant is one character.
5. The value of the variable of type int ranges from −32768 to 32767.
6. The value of unsigned int variable ranges from 0 to 65535.
7. The value of float variable ranges from 0 to 10−38 to 10+38.
8. The symbol for logical or operator is | | .
9. Comments are used to increase the readability of the program.
10. Multi line comments start with /* and ends with */.
Q.2 Choose the correct option:
1. Variables are created in:
a) RAM b) ROM
c) HARD DISK d) CACHE
2. Which of the following is a valid character constant?
a) a b) “b”
c) ‘6’ d) =
3. Which of the data type offers the highest precision?
a) float b) long int
c) long double d) unsigned long int
4. When the result of the computation of two very small numbers is too small to be
represented, this phenomenon is called:
a) Arithmetic overflow b) Arithmetic underflow
c) Truncation d) Round off
5. The predefined words of the programming language that are used for special
purposes in the source program are called:
(a) Keywords (b) Statements
(c) Special words (d) Alphabet
6. How many keywords are in C?
(a) 50 (b) 100
(c) 32 (d) 25
[Ch#9] Elements of C 260 Computer Science Part-II
7. A quantity whose value may change during execution of program is called:
(a) Constant (b) string constant
(c) variable (d) token
8. A quantity whose value cannot change during execution of program is called:
(a) constant (b) keyword
(c) variable (d) token
9.  is not a valid variable name:
(a) 6_XYZ (b) roll_no
(c) XYZ (d) ABC
10. The symbol = represents:
a) Comparison operator b) Assignment operator
c) Equal to operator d) None of these
11. Which of the operator has lowest precedence
a) ! b) +
c) = d) = =
12. Relational operators are used to
a) Establish a relationship among variables.
b) Compare two values.
c) Construct compound conditions.
d) Perform arithmetic operations.
13.  is valid variable name:
(a) 2S (b) 2–S
(c) S–2 (d) S2
14. Which of the following characters cannot be used as first character of a variable
name?
(a) 5 (b) x
(c) a (d) z
15. In C, the maximum length of variable name is:
(a) 25 (b) 256
(c) 31 (d) 15
16. C is a strongly typed language, this means that:
a) Every program must be compiled before execution
b) Every variable must be declared before it is being used
c) The variable declaration also defines the variable
d) Sufficient data types are available to manipulate each type of data
[Ch#9] Elements of C 261 Computer Science Part-II
17. The logical not (!) operator is denoted as:
a) Ternary operator b) Unary operator
c) Binary operator d) Bitwise operator
18. a += b is equivalent to
a) b += a b) a =+ b
c) a = a + b d) b = b + a
19. The words used to write the statements of a program are called
a) Special Words b) Words
c) Keywords d) Alphabets
20.  elements of program in not token:
(a) keyword (b) string constant
(c) variable (d) comment
21. In C, the comments are written in program between:
(a) { } (b) /* */
(c) |* *| (d) < >
22.  is used to declare a real type variable:
(a) int (b) float
(c) long (d) char
23.  data types takes only one byte is memory:
(a) int (b) float
(c) long (d) char
24. An identifier whose value can be changed during execution of a program is called
a) token b) string constant
c) constant d) variable
25. Which of the following is not a valid variable name?
a) 3_a b) c_a
c) int1 d) abc
26. Which character cannot be used in a variable name?
a) _ b) ,
c) a d) c
27. How many bytes, the double data type variable takes in memory?
(a) 1 (b) 2
(c) 4 (d) 8
28. How many bytes the long data type variable takes in memory?
(a) 1 (b) 2
[Ch#9] Elements of C 262 Computer Science Part-II
(c) 4 (d) 8
29. In number 0.123 × 10 , the precision is:
6

(a) 0 (b) 3
(c) 6 (d) 5
30. The float data type variable has a precision of:
(a) 15 (b) 6
(c) 3 (d) 5
31. The double data type variable has precision of:
(a) 15 (b) 6
(c) 3 (d) 5
32. The float data type variable has a range of:
(a) 10−30 to 1030 (b) 10−300 to 10300
(c) 10−38 to 1038 (d) 10−308 to 10308
33. The double data type variable has a range of:
(a) 10−30 to 1030 (b) 10−300 to 10300
(c) 10−38 to 1038 (d) 10−308 to 10308
34. Which of the following is used to declare a real type variable?
a) long b) real
c) float d) cha
35. How many bytes the int data type takes in memory
a) 1 b) 2
c) 4 d) 8
36.  is arithmetic operator:
(a) = (b) ==
(c) % (d) &&
37.  is valid character constant:
(a) a (b) “a”
(c) ‘a’ (d) None
38.  is increment operator:
(a) + (b) =+
(c) ++ (d) --
39.  is a modulus operator:
[Ch#9] Elements of C 263 Computer Science Part-II
(a) ! (b) %
(c) ++ (d) /
40. If a = 19, then after execution of the statement b = a %5; the value of b will be:
(a) 5 (b) 4
(c) 2.71 (d) 2
41. The value returned by expression 3+3*5 will be:
(a) 16 (b) 18
(c) 12 (d) 8
42. How many bytes the float data type takes in memory
a) 1 b) 2
c) 4 d) 8
43. How many bytes the char data type takes in memory
a) 1 b) 2
c) 4 d) 8
44. Which of the following is an arithmetic expression?
a) ab&&cd b) ab+cd
c) !ab d) ab>cd
45.  data type offers the highest precision:
(a) float (b) long int
(c) long double (d) long float
46. How many logical operators are in C?
(a) 4 (b) 3
(c) 2 (d) 6
47.  is arithmetic expression:
(a) a && b (b) a+b
(c) !a (d) a>b
48. +,-,/,% and * are:
(a) Relational operators (b) Logical operators
(c) Arithmetic operators (d) None
49. If x = 3, then after executing the statement “x = x − −;”, the value of x will be:
(a) 2 (b) 3
(c) 1 (d) 4
50. If simple assignment statement is “x = x + 2;”, then its equivalent compound
assignment statement is:
[Ch#9] Elements of C 264 Computer Science Part-II
(a) x ++ = 2 (b) x + = 2;
(c) x = + 2; (d) y = x + 2;
[Ch#9] Elements of C 265 Computer Science Part-II
51. The value of 15%2 is
a) 7 b) 7.5
c) 2 d) 1
52. What will be the value of ‘x’ after executing the following statements?
float y = 6.59;
int x = 2;
x = y;
(a) 2 (b) 6.59
(c) 6 (d) 7
53. What will be the value of ‘x’ after executing the following statements?
int x = 2;
x + = x ++;
(a) 4 (b) 5
(c) 3 (d) 6
54. The names used to represent variables, constants , types functions etc are called
a) Words b) Characters
c) Identifiers d) All of Above
55. There are ____ types of identifiers in C language
a) 2 b) 3
c) 4 d) 1
56. Which one is not an example of standard identifier
a) printf b) if
c) sqroot d) else
57. The reserve words cannot be
a) Used in program b) Redefined
c) Copied d) All of Above
58. Initialization of a variable refers to
a) Value at the time of declaration b) Value at any time with in the program
c) Value after the program execution d) All of Above
59. What will be the value of ‘y’ after executing the following statements?
int y = 3
y = y + (++y);
(a) 8 (b) 7
(c) 4 (d) 6
[Ch#9] Elements of C 266 Computer Science Part-II
60.  is not a valid variable name:
(a) a123 (b) my name
(c) real (d) float
61.  data types is used to store real value:
(a) float (b) double
(c) long double (d) All
62. Which of the following data can be stored by “int” type variable?
(a) “2564” (b) -56.25
(c) 487596 (d) None
63.  statements is not valid:
(a) char char = ‘a’; (b) char ch = ‘a’;
(c) char ch = ‘9’; (d) char ch = ‘A’;
64.  statements is valid for declaring variable(s):
(a) float height; (b) int x, y, z;
(c) double marks, total; (d) All
65. Assigning a value to a variable at the time of its declaration is called:
(a) Initializing (b) Assigning
(c) Declaring (d) Naming
66. Which one is a valid variable name
a) @home b) #home
c) _home d) home+
67. A variable can be declared for ____ data type
a) One b) Two
c) Three d) Multiple
68.  statement is valid for initializing variable(s):
(a) float height = 5.5; (b) int x = 2, y = 5, z = 6;
(c) char ch = ‘D’; (d) All
69.  is valid character constant:
(a) ‘A’ (b) ‘6’
(c) ‘$’ (d) All
[Ch#9] Elements of C 267 Computer Science Part-II
70. The ‘int’ data type variable has a range of:
(a) -32768 to +32767 (b) 0 to 256
(c) 0 to 65536 (d) None
71. An expression may consist of:
(a) operands (b) operators
(c) Both (a) and (b) (d) None
72. An arithmetic expression may consist of:
(a) variables (b) constants
(c) arithmetic operators (d) All
73.  is not an arithmetic operator:
(a) + (b) /
(c) × (d) %
74. The value of expression 2%3 is:
(a) 2 (b) 3
(c) 0 (d) None
75. _________ defines a set of values and a set of operations on those values
a) Data b) Constant
c) Data Type d) None of Above
76. The predefined data types of C language are called
a) User defined data types b) Standard data types
c) Normal data types d) None of Above
77. Which one is not an example of standard data type of C language
a) int b) float
c) char d) real
78. Which range refers to unsigned int data type of C language
a) 0 to 32768 b) 0 to 32767
c) 0 to 65536 d) 0 to 255
79. The value of expression 11%3 is:
(a) 2 (b) 3
(c) 3,66 (d) None
[Ch#9] Elements of C 268 Computer Science Part-II
80. The value of expression 11%3*5 is:
(a) 2 (b) 10
(c) 15 (d) None
81.  valid assignment statement:
(a) x = 10; (b) x = x+y*3;
(c) x = y; (d) All
82.  is valid statement to add 1 to variable x:
(a) x++; (b) x = x +1
(c) x + = 1; (d) All
83. Which range refers to signed int data type of C language
a) -32768 to 32767 b) 0 to 32767
c) 0 to 65536 d) 0 to 255
84. Long double data type of C language requires ____ bytes of memory
a) 2 b) 4
c) 10 d) 8
85.  has higher order of precedence:
(a) + (b) ()
(c) * (d) /
86. How many relational operators in C?
(a) 4 (b) 3
(c) 2 (d) 6
87. Which of the following is relational operator?
(a) = (b) ==
(c) % (d) &&
88.  is not relational operator:
(a) != (b) ==
(c) = (d) <=
89. An expression that uses relational expression is represented by:
(a) Relational expression (b) Arithmetic expression
(c) Logical expression (d) None
[Ch#9] Elements of C 269 Computer Science Part-II
90. A relational expression may return value:
(a) True (b) False
(c) Both a & b (d) None
91. The true value return by relational expression is represented by:
(a) 0 (b) 1
(c) Less then zero (d) None
92.  returns True If X =5 and Y = 10:
(a) X>=Y (b) X >Y
(c) X==Y (d) X!=Y
93.  returns False if X = 5 and Y = 10:
(a) X<Y (b) X <= Y
(c) X>Y (d) X!=Y
94.  operators is used to join two conditions:
(a) Relational operator (b) Arithmetic operator
(c) Assignment operator (d) Logical operator
95.  is logical operator:
(a) AND (b) OR
(c) NOT (d) All of these
96. The logical NOT operator, denoted by !, is a:
(a) Ternary operator (b) Unary operator
(c) Binary operator (d) Bitwise operator
97.  is logical operator:
(a) = (b) ==
(c) % (d) &&
98.  logical operators is unary operator:
(a) && (b) ||
(c) ! (d) None
99. &&, || and ! are:
(a) Relational operators (b) Logical operators
(c) Arithmetic operators (d) None
[Ch#9] Elements of C 270 Computer Science Part-II
100.  symbols is used for logical OR operator:
(a) && (b) ||
(c) ! (d) |
101.  symbols is used for logical AND operator:
(a) && (b) ||
(c) & (d) !
102.  symbols is used for logical NOT operator:
(a) && (b) ||
(c) ! (d) None
103.  is equivalent to !(p>=q):
(a) p=q (b) p<q
(c) p>q (d) !p<q
104.  not a logical operator:
(a) || (b) !
(c) && (d) >
105.  returns True if X = 2 and Y =3:
(a) !(X >Y) (b) (X > Y) || (Y > 2)
(c) (X < Y) && (X>=2) (d) All of these
106.  returns Falst if X = 2 and Y = 3:
(a) (X = = Y) || (Y > X ) (b) (X = = 2) && (Y > 2)
(c) (X < Y) && (X > 2) (d) !(Y >3)
107.  is not a logical operator:
(a) || (b) &&
(c) != (d) !
Q.3 Write T for True and F for false Statements.
1. printf and scanf are standard identifiers. (T)
2. In C language, all variables must be declared before being used. (T)
[Ch#9] Elements of C 271 Computer Science Part-II
3. Standard data types are not predefined in C language. (F)
4. The double data type required 4 bytes memory. (F)
5. In scientific notation the exponent represent the value of the number and
(F)
mantissa represents the power to which it is raised.
6. The symbol for modulus operator is %. (T)
7. The symbol = is used to compare two values. (T)
8. Operator precedence determines the order of evaluation of the operators in
(T)
an expression.
9. For many compilers a C variable name can be up to 31 characters. (T)
10. C program can only use lower case letters in variable names. (F)
Q.4 What data type would you use to represent the following items?
Item Data type
Number of children at you school int
A letter grade on an exam char
The average marks of your class float
Q.5 Which of the following are valid variable name in C?
Sr No Identifier/ Name Valid/invalid Invalid Reason
1) income Valid
2) total marks Invalid Space is not allowed
3) double Invalid C reserve word
4) average-score Invalid Symbol is not allowed
5) room# Invalid Symbol is not allowed
6) _area Valid
7) no_of_students Valid
8) long Invalid Reserve Words
9) Item Valid
10) MAX_SPEED Valid
[Ch#9] Elements of C 272 Computer Science Part-II
Q.6 Let w, x, y and z\ are four float type variables. Let a, b, and c are variables of
int type. Then correct the following statements:

Sr. No Incorrect Statement Correct Statement

1) z=4.0w*y; z=4.0*w*y;

2) y=yz; y=y*z;

3) a=6b4; a=6*b*4;

4) c=3(a+b); c=3*(a+b);

5) z=7w+xy; z=7*w+x*y;

Q.7 Evaluate the expressions.


int a, b, c, d, p;
float v, w, x, y, z;
Values of variable are:
a=2; z=1.3; c=1; d=3; y=0.3E+1;

Sr.# Expression Calculation Result

1) v=a*2.5/y; v=2*2.5/3; 1.666667

2) w=a/y; w=2/3.0; 0.666667

3) p=a/d; p=2/3; 0

4) x=(a+c)/(z+0.3); x=(2+1)/(1.3+0.3)=3/1.6 1.875000

5) b=d/a+d%a; b=3/2+3%2=1+1 2

6) y=c/d*a; y=1/3*2=0*2 0
[Ch#10] Input/Output 282 Computer Science Part-II

Q.1 Fill in the blanks.


1. The getch( ) function does not display character on the output screen.
2. scanf( ) is an input function.
3. %x is a format specifier for hexadecimal integers.
4. Escape Sequence always begins with backslash.
5. The printf() function is defined in stdio.h.
6. The ASCII code for escape key is 27.
7. The escape sequence /r represents carriage return.
8. There are total 80 columns on the output screen.
9. The symbol for address operator is and.
10. \dddd is used to print ASCII code in octal notation.
Q.2 Choose the correct option:
1. The function getch() is defined in:
a) stdio.h b) string.h
c) math.h d) conio.h
2. The escape sequence for backslash is:
a) \ b) \b
c) \\ d) \t
3.  function is used to display output on screen:
(a) scanf() (b) printf()
(c) get() (d) print()
4. The printf() function is used to display:
(a) Text (b) Constants or values of variables
(c) Both a & b (d) None
5.  is not used in control or format string in a printf() function:
(a) Text (b) escape sequences
(c) format specifiers (d) variables
6. How many variables can be used in one printf() function?
(a) Only one (b) Two
[Ch#10] Input/Output 283 Computer Science Part-II
(c) Three (d) Many
7.  is control string in the statement printf(“Result = %d”,r);:
(a) %d (b) Result = %d
(c) r (d) None
8. The functions used for input and output are stored in header file:
(a) conio.h (b) math.h
(c) output.h (d) stdio.h
9.  is used for flag:
(a) + (b) -
(c) Both a and b (d) None
10. The format specifier %u is used for:
a) integer b) Unsigned Short int
c) Unsigned float d) Unsigned long int
11. The escape sequence for carriage return is
a) \a b) \c
c) \r d) \f
12. Which of the following forma specifier is used for character type data
a) \c b) %c
c) %s d) %ch
13. What will be the output of printf(“%d”,’a’); ?
a) 65 b) A
c) 97 d) a
14.  format specifiers is used for integer type data:
(a) %d (b) %s
(c) %c (d) %f
15.  format specifiers is used for float type data:
(a) %d (b) %s
(c) %c (d) %f
16. The %x is a format specifier for:
(a) long integer value (b) octal value
(c) hexadecimal value (d) double value
17. How many digits are printed to the right of the decimal point in real number?
(a) 15 (b) 3
[Ch#10] Input/Output 284 Computer Science Part-II
(c) 6 (d) 5
18.  is used with format specifier to display output left-justified:
(a) % (b) +
(c) - (d) *
19. The escape sequence to insert horizontal tab is
a) \r b) \f
c) \tab d) \t
20. Which of the following format specifier is used for string type data?
a) %s b) %c
c) %f d) %string
21. What will be the output of printf(“%.3f”,3.45678); ?
a) 345678 b) 3.45678
c) 3.457 d) none of above
22. What will be the output of printf(“%d”, ‘A’); ?
(a) A (b) 65
(c) ‘A’ (d) 97
23. Which will be the output of printf(“%c”, ‘A’); ?
(a) A (b) 65
(c) ‘A’ (d) 97
24.  is the general form of format specifier for real value:
(a) m.n%f (b) %m.nf
(c) %fm.n (d) None
25. What will be the output of printf(“% .2f”, 5.555); ?
(a) 5.555 (b) 5.55
(c) 5.56 (d) 5.00
26.  characters indicates the beginning of escape sequence:
(a) \ (b) /
(c) | (d) %
27. The escape sequence to insert tab in C is:
(a) \n (b) \t
(c) \r (d) \f
28.  is used to move the cursor at the beginning of current line:
(a) \n (b) \t
[Ch#10] Input/Output 285 Computer Science Part-II
(c) \r (d) \f
29.  can be used to begin a new line in C:
(a) \n (b) \a
(c) \r (d) \b
30. The escape sequence to produce beep from computer speaker is:
(a) \t (b) \a
(c) \n (d) \b
31.  is a correct statement to print “Pakistan” in double quotes:
(a) printf(““Pakistan””); (b) printf(“\”Pakistan”\”)
(c) printf(“\”Pakistan\””); (d) None
32. The field width will automatically _________ if the specified space is not
sufficient to accommodate the value
a) Adjusted b) Shrink
c) Expand d) All of Above
33. A format specifier always begins with the __ symbol
a) % b) \
c) / d) %d
34. Escape sequence characters always begins with a ___ character
a) % b) \
c) / d) %d
35. Which characters cause an escape from the normal interpretation of a string so
that the next character is recognized as having a special meaning.
a) Format String b) Format Specifier
c) Special Characters d) Escape Sequences
36.  is a correct statement to input value to a variable ‘x’ of float data type:
(a) scanf(“%f”, x); (b) scanf(x);
(c) scanf(“%f’,&x); (d) scanf(&x);
37. The ampersand (&) used in “scanf()” function is called:
(a) address indicator (b) cell address
(c) binary operator (d) address operator
38. The function getche() is defined in:
[Ch#10] Input/Output 286 Computer Science Part-II
(a) stdio.h (b) string.h
(c) math.h (d) conio.h
39. Which escape sequence is used for backspace
a) \B b) \b
c) /b d) /s
40. scanf() function is used to get data from the
a) computer b) processor
c) input device d) program
41.  is used to get input from user during program execution:
(a) scanf() (b) gets()
(c) getche() (d) All of these
42.  is used to get input from user into any types of variables during the
execution of program:
(a) scanf() (b) gets()
(c) getche() (d) getch()
43. Instead of the variable name the scanf() requires _________ of the variable to
store the input value into it
a) Name b) Address
c) Operator d) Data
44. Which character is used as address of operator
a) $ b) ?
c) # d) &
45. getch() function is used to input ____ character
a) One b) Many
c) Two d) All of Above
46. getche() function is used to input ____ character
a) One b) Many
c) Two d) All of Above
47. Which input function will not print the entered character on the screen
[Ch#10] Input/Output 287 Computer Science Part-II
a) scanf() b) getch()
c) getche() d) getline()
Q.3 Write T for True and F for false Statements.
1. printf and scanf are standard identifiers. (T)
2. In C language, all variables must be declared before being used. (T)
3. Standard data types are not predefined in C language. (F)
4. The double data type required 4 bytes memory. (F)
5. In scientific notation the exponent represent the value of the number and
(F)
mantissa represents the power to which it is raised.
6. The symbol for modulus operator is %. (T)
7. The symbol = is used to compare two values. (T)
8. Operator precedence determines the order of evaluation of the operators in
(T)
an expression.
9. For many compilers a C variable name can be up to 31 characters. (T)
10. C program can only use lower case letters in variable names. (F)
Q4. Show the output displayed by the program when the data entered are 10 and 15.
Answer:
#include<stdio.h>
#include<conio.h>
void main()
{
int m, n;
printf(“ Enter two numbers separated by comma”);
scanf(“%d %d”, &m, &n);
m = m + 10;
n = 5 * m;
printf(“m = %d\t\t\t n=%d \n”,m,n);
}
Output:
Enter two numbers separated by comma 10, 15
m = 20 n = 100
Q5. Show the output of the variables m, n before and after the execution of the
above program.

Answer:
[Ch#10] Input/Output 288 Computer Science Part-II
#include<stdio.h>

#include<conio.h>

void main()

{
int m, n;
clrscr();
printf(“\nContents before Execution\nm=%d\t\t\tn=%d \n”,m,n);
printf(“ Enter two numbers separated by comma”);
scanf(“%d %d”, &m, &n);
m = m + 10;
n = 5 * m;
printf(“\nContents after Execution \nm = %d\t\t\t n=%d \n”,m,n);
}
Output:
Contents before Execution
m= 25308 n = 72830
Enter two numbers separated by comma 10, 15
Contents after Execution
m = 20 n = 100
Q6. Character is input by the user and print ASCII code of character:
Answer:
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(“Enter a character “);
[Ch#10] Input/Output 289 Computer Science Part-II
ch=getche();
printf(“\nASCII code for %c is %d”, ch, ch);
}
Q7. Character is input by the user and print ASCII code of character use scnaf()
function:
Answer:
#include<stdio.h>
void main()
{
char ch;
printf(“Enter a character “);
scanf(“%c”, &ch);
printf(“\nASCII code for %c is %d”, ch, ch);
}
Q8. Show how the value -17.246 would be pinted using the formats %8.4f,
%8.3f, %8.2f, %8.1f, %8.0f, and %0.2f
Answer:
Statement Output(� represents spaces)
printf(“%8.4f”,-17.246); -17.2460
printf(“%8.3f”,-17.246); �-17.246
printf(“%8.2f”,-17.246); � �-17.25
printf(“%8.1f”,-17.246); � � �-17.2
printf(“%8.0f”,-17.246); � � � � �-17
printf(“%0.2f”,-17.246); -17.25
Q9. Assuming x (type double) is 21.335 y (type int) is 200 Show output of the
following statement on paper
Answer:
Statement Output(�represents spaces)
[Ch#10] Input/Output 290 Computer Science Part-II

printf(“x is %6.2f\t y is %4d\n”, x, y); x is �21.34 y is �200


printf(“y is %d \n”, y); y is 200
printf(“x is %.1f\n”, x); x is 21.3
Q10. If the variables a, b and c are 307, 408.558 and -12.31 respectively, write a
statement that will display the following line:
_ _307_ _ _ _ _408.558_ _ _ _-12.31
Answer:
printf(“%5d %11.3f %9.2f”, a, b, c);
Q11. Write a program that gets the radius of the circle and calculate the area (=
pi*radius2) of circle.
Answer:
#include<stdio.h>
#include<conio.h>
void main()
{
float r,area;
#define pi 3.14159
clrscr();
printf(“Enter radius of circle : “);
scanf(“%f”, &r)
area = pi*r*r;
printf(“\nArea of circle = %.2f”, area);
}
Q12. Write a program that store the values ‘A’, ‘U’, 3.456E10 and 50 in separate
memory cells. The program should get the first three values as input data,
but use assignment operator to store last value. The first two values are
characters, third value is real, last value is integer
Answer:
#include<stdio.h>
#include<conio.h>
void main()
{
float f;
char ch1, ch2;
int k;
clrscr();
printf(“Enter first character : “);
ch1=getche();
printf(“Enter second character : “);
ch2=getche();
printf(“Enter float value : “);
[Ch#10] Input/Output 291 Computer Science Part-II
scanf(“%E”, &f);
k = 50;
printf(“\nCharacters are %c and %c ”, ch1, ch2);
printf(“\nfloat value is %8.3E ”, f);
printf(“\nInteger value is %d ”, k);
}
Q13. Write a program that converts Fahrenheit temperature to Celsius
(centigrade temperature).
Answer:
#include<stdio.h>
#include<conio.h>
void main()
{
float f, c;
clrscr();
printf(“Enter temperature in Fahrenheit: “);
scanf(“%f”, &f);
c = 5.0/9.0*(f-32);
printf(“\n Temperature in Celsius = %f”, c);
}
Output:
Enter temperature in Fahrenheit: 212
Temperature in Celsius = 100.000000
Q14. Write a program that takes a positive number with a fractional part and
rounds it to two decimal places.
Answer:
#include<stdio.h>
#include<conio.h>
void main()
{
float f;
clrscr();
printf(“Enter a Number: “);
scanf(“%f”, &f);
printf(“\n Rounded Number = %10.2f”, f);
}
Output:
Enter a Number: 756.258563
Rounded Number = 756.26
Q15. Perform arithmetic operations:
Answer:
#include<stdio.h>
void main ( )
{
float a,b;
[Ch#10] Input/Output 292 Computer Science Part-II
printf(“\n Enter two Numbers : “);
scanf(“%f %f”, &a,&b);
printf(“\n Addition = %.2f”,a+b);
printf(“\n Subtraction = %.2f”,a-b);
printf(“\n Multiplication = %.2f”,a*b);
printf(“\n Division = %.2f”,a/b);
}
Q16. Calculate area and perimeter of a triangle (input three sides):
Answer:
#include<stdio.h>
#include<math.h>
void main ( )
{
float a,b.c,s,area,p;
printf(“\n Enter first side : “);
scanf(“%f”, &a);
printf(“\n Enter 2nd side : “);
scanf(“%f”, &b);
printf(“\n Enter 3rd side : “);
scanf(“%f”, &c);
s=(a+b+c)/2;
p=a+b+c;
area = sqrt(s*(s-a)*(s-b)*(s-c));
printf(“\n Perimeter = %.2f”, p);
printf(“\n AREA = %.2f”, area);
}
Q17. Swapping the values of two variables.
Answer:
#include<stdio.h>
void main( )
{
int a,b,c;
printf(“\n Enter first Number : “);
scanf(“%f”, &a);
printf(“\n Enter 2nd Number : “);
[Ch#10] Input/Output 293 Computer Science Part-II
scanf(“%f”, &b);
c=a;
a=b;
b=c;
printf(“\n Value of A= %d\t Value of B = %d”,a,b);
}
[Ch#11] Decision Constructors 316 Computer Science Part-II

Q.1 Fill in the Blanks:


1. Control structure controls the flow of execution in the program.
2. Compound statement is a group of statement enclosed in braces.
3. The if statement is used to select a path flow in a program based on a condition.
4. A flow chart is a pictorial representation of a program.
5. Nested if refers to the structure with one if statement inside another if statement.
6. The switch case statement can be used as alternative to if-else if statement.
7. In switch statement the value of expression must be integer or character.
8. The break statement switches the control outside the block in which it is used.
9. The purpose of default label in switch-case statement is the same as that of else in
if-else statement.
10. A condition is an expression that is either true or false.
Q.2 Choose the correct option:
1. Which of the following is not a decision making statement
a) switch b) for
c) if-else d) if
2. Which of the following operator is used as decision making statement
a) ++ b) --
c) && d) conditional operator
3. How many basic control structures are there?
(a) 1 (b) 2
(c) 3 (d) 4
4. Which one is a control structure?
(a) Selection (b) Sequence
(c) Repetition (d) All
5.  control structures executes program statements one after another:
(a) Selection (b) Sequence
(c) Repetition (d) None
6. The selection statement is also known as:
(a) Decision making statement (b) Compound statement
(c) Repetition Statement (d) Both (a) and (b)
[Ch#11] Decision Constructors 317 Computer Science Part-II
7. Another name of conditional operator is
a) Unary Operator b) Binary operator
c) Ternary Operator d) Bitwise operator
8. Which of the following keywords is not used in switch statement?
a) default b) if
c) case d) switch
9. Which of the following is an optional part in switch statement?
a) default b) break
c) switch d) case
10.  structures is a selection structure:
(a) if (b) if-else
(c) switch (d) All of these
11.  selection structures is the simplest form of decision making structure:
(a) if-else (b) if
(c) switch (d) nest if-else
12.  is not decision-making statement:
(a) if (b) break
(c) Nested if (d) switch
13. Which of the following operators is used as decision-making statement?
(a) increment operator (b) size of operator
(c) && operator (d) conditional operator
14.  is used for making two-way decision:
(a) if-else (b) if
(c) Nested if (d) switch
15.  is not used for making two-way decision:
(a) if (b) conditional operator
(c) if-else (d) All
16. The conditional operator is an alternative of:
(a) if (b) simple if-else
(c) nested if (d) None
17. The conditional operator takes _________ expression.
(a) one (b) two
[Ch#11] Decision Constructors 318 Computer Science Part-II
(c) three (d) None
18. Which operator in C language is called ternary operator?
(a) if (b) ++
(c) ?: (d) ()
19. What will be the output of (7 > 8) ? printf(“ABC”):printf(“XYZ”);
(a) ABC (b) XYZ
(c) ABCXYZ (d) All
20. The last statement of each case in switch statement must be a:
(a) default statement (b) if-else statement
(c) break statement (d) is statement
21. __________structures are used to control the flow of execution in a program
a) Data b) Program
c) Input d) Control
22. Which one is not a control structure
a) Selection b) Input / Output
c) Sequence d) Repetition
23. A group of statements enclosed in opening and closing braces is called
a) Group Statement b) Program Statement
c) Compound Statement d) All of Above
24. A ___________structure chooses which statement or a block of statements is to
execute
a) Selection b) Input / Output
c) Sequence d) Repetition
25. Which one is not a selection structure
a) if – else b) switch
c) if d) iff-else
26. The case block ends with:
(a) end select (b) end case
(c) break (d) case else
27. The value that cannot be used in expression of switch statement
a) int b) float
c) char d) long
28. If the value of switch expression is float compiler will
[Ch#11] Decision Constructors 319 Computer Science Part-II
a) Generate error b) Give wrong result
c) Smooth execution d) None of Above
29.  is suitable when multiple choices are given and one choice is to be
selected:
(a) if-else (b) if
(c) break statement (d) switch
30. In switch statement, each case label may be an integer or:
(a) String (b) Real
(c) Character (d) All
31. When two case labels are used without having any other statement in between
them they work as _______ operator
a) AND b) NOT
c) OR d) None of Above
32. Which statement in switch case structure cause rest of the statements to be
skipped?
a) case b) default
c) break d) All of Above
33. In if-else-if statement only_____ block(s) of statements is executed
a) One b) Two
c) Three d) None of Above
34. Which expression can be used in if condition?
a) Relational b) Logical
c) Arithmetic d) All of Above
Q.3 Write T for True and F for false Statements.
1. An arithmetic expression can not be used as condition in if statement (T)
2. The conditional operator is ternary operator (T)
3. Logical expression are used to compare values (F)
4. A switch statement can not be used within a block of if statement (F)
5. The break statement stops the execution of a program for a moment and
(F)
then resumes.
6. In sequence structure, the statements are executed in the same order in
(T)
which they appear in the program.
7. A false condition always evaluates to zero (T)
8. Use of statement terminator at the end of an if statement causes a syntax
(F)
error.
[Ch#11] Decision Constructors 320 Computer Science Part-II
9. The switch statement can not be of float or double type. (T)
10. C is an unstructured programming language. (F)
Q.4 Rewrite the program of vowels given in example using if statement.
Answer:
#include<stdio.h>
#include<conio.h>
void main ( )
{
char ch;
printf(“\n Enter any character :=> ”);
scanf(“%c”, &ch);
if(ch==’A’ || ch==’a’)
printf(“\n It is a vowel “);
else if(ch==’E’ || ch==’e’)
printf(“\n It is a vowel “);
else if(ch==’I’ || ch==’i’)
printf(“\n It is a vowel “);
else if(ch==’O’ || ch==’o’)
printf(“\n It is a vowel “);
else if(ch==’U’ || ch==’u’)
printf(“\n It is a vowel “);
else
printf(“\n It is a consonant “);
}
OR
#include<stdio.h>
#include<conio.h>
void main ( )
{
char ch;
printf(“\n Enter any character : “);
scanf(“%c”, &ch);
if(ch==’A’ || ch==’a’ || ch==’E’ || ch==’e’ || ch==’I’ || ch==’i’ || ch==’O’ ||
ch==’o’ || ch==’U’ || ch==’u’)
printf(“\n It is a vowel “);
[Ch#11] Decision Constructors 321 Computer Science Part-II
else
printf(“\n It is a consonant “);
}
Q.5 Attempt the following parts Assume x = 10.0, y = 15.0, what are the values of
the following conditions.
Answer:
Statement Result 0 means false 1 means true
x != y 1
x<x 0
x >= y-x 1
x == y +x – y 1
Write an expression to test each of the following relationships.
Statement Program Statement
Age is from 18 to 25 (age >= 18 && age<=25)
Temperature is less than 40.0 and greater than (temperature < 40.0 && temperature
25.0 > 25.0)
Year is divisible by 4 (year % 4 == 0)
Speed is not greater than 80 ( ! (speed > 80) )
Y is greater than x and less than z (y > x && y < z)
W is either equal to 6 or not greater than 3 ((w==6) || (!(w>3))
Assigns a value 1 to the variable test if k is in the if(k>=-m && k<=m)
range –m through +m test=1;
Assigns a value of 1 to the variable lowercase if if(ch>=97 && ch<=122)
ch is a lowercase letter, otherwise assign 0 lowercase = 1
else
lowercase = 0
Assigns a value 1 to the variable divisor if m is a if(n%m==0)
[Ch#11] Decision Constructors 322 Computer Science Part-II
divisor of n; otherwise assign 0 divisor = 1
else
divisor = 0
Q6. Write an interactive program that contains the if Statement that may be used
to compute the area of a square or a area of a triangle after prompting the
user to type the first character of the figure name sort.
Answer:
#include<stdio.h>
#include<conio.h>
void main ( )
{
char ch;
float area, s, b, h;
printf(“\n Enter character S for Square Area: “);
printf(“\n Enter character T for triangle Area: “);
scanf(“%c”, &ch);
if(ch==’S’ || ch==’s’)
{
printf(“\n Enter Side of a Square== ”);
scanf(“%f”, &s);
area = s*s;
printf(“\n Area of a square is = %.2f”, area);
}
else if(ch==’T’ || ch==’t’)
{
printf(“\n Enter Base of a triangle== ”);
scanf(“%f”, &b);
printf(“\n Enter height of a triangle== ”);
scanf(“%f”, &h);
area = 0.5*b*h;
printf(“\n Area of a triangle is = %.2f”, area);
}
else
printf(“\n You Entered A Wrong Key == ?”);
}
Q7. Perform arithmetic operations using if-else-if
Answer:
#include<stdio.h>
#include<conio.h>
void main ( )
[Ch#11] Decision Constructors 323 Computer Science Part-II
{
float a,b;
int op;
printf(“\n Enter two Numbers : “);
scanf(“%f %f”, &a, &b);
printf(“\n Enter 1 for Addition : “);
printf(“\n Enter 2 for Subtraction : “);
printf(“\n Enter 3 for Multiplication : “);
printf(“\n Enter 4 for Division : “);
printf(“\n Now please press 1 2 3 or 4 : “);
scanf(“%d”, &op);
if(op==1)
printf(“The Result = %.2f”,a+b);
else if(op==2)
printf(“The Result = %.2f”,a-b);
else if(op==3)
printf(“The Result = %.2f”,a*b);
else if(op==4)
printf(“The Result = %.2f”,a/b);
else
printf(“ Choice is invalid “);
}
Q8. Perform arithmetic operations using switch
Answer:
#include<stdio.h>
#include<conio.h>
void main ( )
{
float a,b;
int op;
printf(“\n Enter two Numbers : “);
scanf(“%f %f”, &a, &b);
printf(“\n Enter 1 for Addition : “);
printf(“\n Enter 2 for Subtraction : “);
printf(“\n Enter 3 for Multiplication : “);
[Ch#11] Decision Constructors 324 Computer Science Part-II
printf(“\n Enter 4 for Division : “);
printf(“\n Now please press 1 2 3 or 4 : “);
scanf(“%d”, &op);
switch(op)
{
case 1:
printf(“The Result = %.2f”,a+b);
break;
case 2:
printf(“The Result = %.2f”,a-b);
break;
case 3:
printf(“The Result = %.2f”,a*b);
break;
case 4:
printf(“The Result = %.2f”,a/b);
break;
default:
printf(“ Choice is invalid “);
}
}
Q9. Perform arithmetic operations using if-else-if
Answer:
#include<stdio.h>
#include<conio.h>
void main ( )
{
float a,b;
char op;
printf(“\n Enter two Numbers : “);
scanf(“%f %f”, &a, &b);
printf(“\n Enter a for Addition : “);
printf(“\n Enter s for Subtraction : “);
printf(“\n Enter m for Multiplication : “);
printf(“\n Enter d for Division : “);
printf(“\n Now please press a s m or d : “);
op=getche( );
if(op==’a’ || op==’A’)
printf(“The Result = %.2f”,a+b);
else if(op==’s’ || op==’S’)
printf(“The Result = %.2f”,a-b);
else if(op==’m’ || op==’M’)
[Ch#11] Decision Constructors 325 Computer Science Part-II
printf(“The Result = %.2f”,a*b);
else if(op==’d’ || op==’D’)
printf(“The Result = %.2f”,a/b);
else
printf(“ Choice is invalid “);
}
Q10. Write a program that inputs temperature and displays a message according
to the following data.
Temperature Message
Greater than 35 Hot Day
Between 25 and 35(inclusive) Pleasant Day
Less than 25 Cool day
Answer:
#include<stdio.h>
#include<conio.h>
void main ( )
{
float temp;
printf(“\n Enter Temperature : “);
scanf(“%f”, &temp);
if (temp>35)
printf(“\n It is a HOT DAY”);
else if (temp <= 35 && temp >= 25)
printf(“\n It is a PLEASANT DAY”);
else
printf(“\n It is a COOL DAY”);
}
Q11. Write a program that inputs obtained marks of a student, then calculates
percentage and grade of a student according to the following rules (Assume
Total marks are 1100).
Percentage Grade
More Than or equal to 80 A+
Between 70(inclusive) and 80 A
Between 60(inclusive) and 70 B
Between 50(inclusive) and 60 C
Between 40(inclusive) and 50 D
Between 33(inclusive) and 40 E
Less than 33 F
Answer:
[Ch#11] Decision Constructors 326 Computer Science Part-II
#include<stdio.h>
#include<conio.h>
void main ( )
{
float marks, per;
printf(“\n Enter Obtained Marks out of 1100 =:”);
scanf(“%f”, &marks);
per = marks/1100*100;
if (per >= 80)
printf(“\n GRADE = A+”);
if (per >= 70 && per < 80)
printf(“\n GRADE = A”);
if (per >= 60 && per < 70)
printf(“\n GRADE = B”);
if (per >= 50 && per < 60)
printf(“\n GRADE = C”);
if (per >= 40 && per < 50)
printf(“\n GRADE = D”);
if (per >= 33 && per < 40)
printf(“\n GRADE = E”);
if (per < 33)
printf(“\n GRADE = F”);
}
Q12. Write a program that input x and y co-ordinates of a point in the coordinate
plane and determine the location of point.
Answer:
#include<stdio.h>
#include<conio.h>
void main ( )
{
int x, y;
printf(“\n Enter X and Y values for a point : “);
scanf(“%d %d”, &x, &y);
if (x == 0 && y == 0) printf(“\n POINT IS ORIGIN”);
[Ch#11] Decision Constructors 327 Computer Science Part-II
if (x > 0 && y == 0)
printf(“\nPOINT IS ON X-AXIS right side of origin ”);
if (x < 0 && y == 0)
printf(“\n POINT IS ON X-AXIS LEFT SIDE OF origin ”);
if (x == 0 && y > 0)
printf(“\n POINT IS ON Y-AXIS AND ABOVE THE X-AXIS”);
if (x == 0 && y < 0)
printf(“\n POINT IS ON Y-AXIS AND BELOW THE X-AXIS”);
if (x > 0 && y > 0)
printf(“\n POINT IS IN FIRST QUADRANT”);
if (x > 0 && y < 0)
printf(“\n POINT IS IN FOURTH QUADRANT”);
if (x < 0 && y > 0)
printf(“\n POINT IS IN SECOND QUADRANT”);
if (x < 0 && y < 0)
printf(“\n POINT IS IN THIRD QUADRANT”);
}
Q13. Get a Number from user and find it square, cube, or square root on user
choice using if-else statement.
Answer:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main ( )
{
float a;
int ch;
printf(“\n Enter Number : “);
scanf(“%f”, &a);
printf(“\n Enter 1 for Square : “);
printf(“\n Enter 2 for Cube : “);
printf(“\n Enter 3 for Square Root : “);
printf(“\n Now please press 1 2 or 3 : “);
[Ch#11] Decision Constructors 328 Computer Science Part-II
scanf(“%d”,&ch);
if(ch==1)
printf(“The Result = %.2f”,a*a);
else if(ch==2)
printf(“The Result = %.2f”,a*a*a);
else if (ch==3)
printf(“The Result = %.2f”,sqrt(a));
else
printf(“ Choice is invalid “);
}
Q14. Get a Number from user and find it square, cube, or square root on user
choice using if-else statement.
Answer:
#include<stdio.h>
#include<math.h>
void main ( )
{
float a;
char ch;
printf(“\n Enter Number : “);
scanf(“%f”, &a);
printf(“\n Enter S for Square : “);
printf(“\n Enter C for Cube : “);
printf(“\n Enter R for Square Root : “);
printf(“\n Now please press S C or R : “);
scanf(“%c”, &ch);
if(ch==’S’ || ch==’s’)
printf(“The Result = %.2f”,a*a);
else if(ch==’C’||ch==’c’)
printf(“The Result = %.2f”,a*a*a);
else if (ch==’R’||ch==’r’)
printf(“The Result = %.2f”,sqrt(a));
else
printf(“ Choice is invalid “);
}
[Ch#11] Decision Constructors 329 Computer Science Part-II
Q15. Get a Number from user and find it square, cube, or square root on user
choice using switch statement.
Answer:
#include<stdio.h>
#include<math.h>
void main ( )
{
float a;
char ch;
printf(“\n Enter Number : “);
scanf(“%f”, &a);
printf(“\n Enter S for Square : “);
printf(“\n Enter C for Cube : “);
printf(“\n Enter R for Square Root : “);
printf(“\n Now please press S C or R : “);
scanf(“%c”, &ch);
switch(ch)
{
case ’S’:case ‘s’:
printf(“The Result = %.2f”,a*a);
break;
case ’C’:case ‘c’:
printf(“The Result = %.2f”,a*a*a);
break;
case ’R’:case ’r’:
printf(“The Result = %.2f”,sqrt(a));
break;
default:
printf(“ Choice is invalid “);
}
}
Q16. Program: Get a Number from user and find it square, cube, or square root
on user choice using switch statement.
[Ch#11] Decision Constructors 330 Computer Science Part-II
Answer:
#include<stdio.h>
#include<math.h>
void main ( )
{
float a;
int ch;
printf(“\n Enter Number : “);
scanf(“%f”, &a);
printf(“\n Enter 1 for Square : “);
printf(“\n Enter 2 for Cube : “);
printf(“\n Enter 3 for Square Root : “);
printf(“\n Now please press 1 2 or 3 : “);
scanf(“%d”, &ch);
switch(ch)
{
case 1:
printf(“The Result = %.2f”,a*a);
break;
case 2:
printf(“The Result = %.2f”,a*a*a);
break;
case 3:
printf(“The Result = %.2f”,sqrt(a));
break;
default:
printf(“ Choice is invalid “);
}
}
[Ch#12] Loop Constructors 355 Computer Science Part-II

Q.1 Fill in the blanks:


1. There are three types of loops in C.
2. The loop condition controls the loop repetition.
3. In do while loop, first the body of loop is executed and the test condition is
checked.
4. nested loop means a loop within the body of another loop.
5. The goto statement performs an unconditional transfer of control to the named
label.
6. Repetition of statement in a program is called loop.
7. There are three expressions in for loop statement.
8. The body of while loop executes only if the specified condition is true.
9. Increase in the level of nesting increases the complexity of the nested loop.
10. A label is meaningful only to a goto statement.
Q.2 Choose the correct option:
1. How many types of loop structures are in C?
(a) 3 (b) 2
(c) 4 (d) 5
2.  is a loop statement:
(a) if (b) while
(c) if-else (d) switch
3. The loop which never ends is called:
(a) for loop (b) nested loop
(c) infinite loop (d) All
4.  loop structures are available in C language:
(a) do-while (b) while
(c) for (d) All of these
5.  is called counter loop:
(a) do-while (b) while
(c) for (d) Both (a) & (b)
[Ch#12] Loop Constructors 356 Computer Science Part-II
6. Which one is not a loop structure
(a) switch (b) for
(c) while (d) do-while
7. A variable whose value controls the number of iterations is known as _________.
(a) Variable (b) Control Variable
(c) Loop Variable (d) Loop Control Variable
8. In while loop, the loop control variable always initialized _________.
(a) Before the loop starts (b) Inside the loop body
(c) After the loop ends (d) Outside the program
9. In while loop, the increment / decrement statement are placed _________.
(a) Before the loop starts (b) Inside the loop body
(c) After the loop ends (d) Outside the program
10.  structure executes the body of loop at least once:
(a) do-while (b) while
(c) for (d) None
11. The body of loop comes after the test condition in:
(a) do-while (b) while
(c) for (d) Both (b) and (c)
12. The while loop is also called:
(a) conditional loop (b) wend loop
(c) counter loop (d) Attribute
13. The body of loop comes before the test condition in:
(a) do-while (b) while
(c) for (d) None
14. Semicolon is placed at the end of condition in:
(a) while loop (b) do-while loop
(c) switch (d) All of these
15. The do-while loop ends with a ____
(a) } (b) )
(c) , (d) ;
16. The _____ loop will execute at least even the condition is false
(a) while (b) do-while
(c) for (d) All of above
[Ch#12] Loop Constructors 357 Computer Science Part-II
17. The _____________ of for loop executed only once in the first iteration
(a) Loop condition (b) Increment / decrement
(c) Initialization expression (d) All of above
18.  is related to loop structures:
(a) Body of loop (b) Loop control variable
(c) Condition (d) All of these
19.  structure is used when programmer does not know is advance the
number of repetition of loop?
(a) do-while (b) for
(c) while (d) Both (a) and (c)
20. Loop with in a loop is called
(a) Loops (b) Multiple Loops
(c) Many Loops (d) Nested Loops
21. What is the final value of x when the code int x; for(x=0;x<10;x++){} is run
(a) 10 (b) 9
(c) 1 (d) 0
22. Examine the following code and tell output
int count=1; while(count<5){ printf(“%d”,count); }
(a) 1234 (b) 12345
(c) 111111….. (d) 234
23. Examine the following code and tell output
int count=-2; while(count<3){ printf(“%d”,count); count+ = 1;}
(a) -2-11234 (b) -2-1123
(c) -3-4-5-6-7 (d) -2-1012
24. One execution of the body of loop is called:
(a) iteration (b) duration
(c) cycle (d) Text
25. What will be the value of ‘x’ after executing for(x=1 ; x<15;x++); ?
(a) 14 (b) 1
(c) 16 (d) 15
26. How many times does the loop get iterated?
for(i=0;i=10;i+=2) printf(“Hi\\n”);
(a) 10 (b) 2
(c) 5 (d) None of Above
[Ch#12] Loop Constructors 358 Computer Science Part-II
27. In a group of nested loops, which loop is executed the most number of times?
(a) The outermost loop (b) The innermost loop
(c) All loops at the same number of times (d) Cannot be determined
28. What will be value of c after the execution of following statements?
c=-8; do{c++;}while(c>=5);
(a) -8 (b) -6
(c) -7 (d) -9
29.  is used to move the control to the start of loop body:
(a) continue (b) break
(c) switch (d) None
30.  can be used to terminate the loop::
(a) terminate (b) break
(c) stop (d) exit
31. A special value that terminates the loop is called:
(a) terminate value (b) sentinel value
(c) control value (d) end value
32. The for loop contains three expressions: initialization, test, and:
(a) Character (b) Float
(c) increment/decrement (d) All
33. What will be the output of following code?
int x=5,c=0; If(x%2==1){for(;c<=5;c++) printf(“%d”,c);}
(a) 0123456 (b) 012345
(c) 6 (d) Error Message
34. Which for loop will counts from 0 to 5?
(a) for(int c=0; c<=6;c++) (b) for(c=0; c<5; c++);
(c) for(c=0; c<=5; c++) (d) for(int c=0; c<7; c++)
35. What will be the value of ‘x’ after executing the following code?
int x = 5;
while (++x > 5)
break;
printf(“%d”,x);

(a) 5 (b) 6
(c) 0 (d) None
[Ch#12] Loop Constructors 359 Computer Science Part-II
36. What will be the output of the following code segment?
int n = 5;
while (n > 5)
n * = 10;
printf(“%d”, n );
(a) 5 (b) 10
(c) 50 (d) 0
37. What will be the output of the following code segment?
int m = 10, n = 100;
do
{
m = m + (n ++);
m ++ ;
}while (m < 10);
printf(“%d”, m );
(a) 10 (b) 110
(c) 111 (d) 112
38. What will be the output of the following code segment?
int x = 0;
for (x = 100; x = = 200; x ++);
printf(“%d”, x );
(a) 101 (b) 100
(c) 201 (d) 200
39. What will be the output of the following code segment?
int n = 0
for (;;)
{
if (n = = 10) break;
n++;
}
printf(“%d”, n );
(a) 0 (b) 10
[Ch#12] Loop Constructors 360 Computer Science Part-II
(c) 11 (d) 12
40. What is the final value of x when the code intx; for(x=0; x<10; x++) is run?
(a) 10 (b) 9
(c) 0 (d) 1
Q.3 Write T for true and F for false statements.
1. There is no difference between while and do-while loop. (F)
2. The body of while loop may or may not execute. (T)
3. The do-while loop always executes at least once. (T)
4. The var++ is an example of prefix increment operator. (F)
5. The condition of an infinite loop never becomes true. (F)
6. Initialization expression is option in for loop. (T)
7. The for(i = 1; i < = 10; i++); is an infinite loop. (F)
8. Loop is a decision making construct. (F)
9. A while loop can not be used in the body of a for loop. (F)
10. In type casting, a variable of one type behaves as the variable of (T)
another type temporarily.
Programs using loops:
Q4. To print and find the sum of 10 natural numbers (1+2+3+ -----) using for loop
Answer:
#include<stdio.h>
void main ( )
{
int n,sm=0;
for(n=1;n<=10;n++)
{
printf(“\n %d”,n);
sm=sm+n;
}
printf(“\n The sum of 10 natural numbers = %d”,sm);
}
Q5. Print and find the sum of 10 numbers which are multiple of 5 (5+10+15+ -----
--) using for loop
Answer:
#include<stdio.h>
void main ( )
{
int n, sm=0;
for(n=5;n<=50;n+=5)
[Ch#12] Loop Constructors 361 Computer Science Part-II
{
printf(“\n %d”,n);
sm=sm+n;
}
printf(“\n The sum of numbers = %d”, sm);
}
Q6. Program: Print and find the sum of 10 natural numbers (1+2+3+ ---------)
Using While loop
Answer:
#include<stdio.h>
void main ( )
{
int n=1,sm=0;
while(n<=10)
{
printf(“\n %d”,n);
sm=sm+n;
n++;
}
printf(“\n The sum of 10 natural numbers = %d”,sm);
}
Q7. Print and find the sum of 15 even numbers (2+4+6+ -----) using do-while loop
Answer:
#include<stdio.h>
void main ( )
{
int n=2,sm=0;
do
{
printf(“\n %d”,n);
sm=sm+n;
n+=2;
}
while(n<=30);
printf(“\n The sum of 15 even numbers = %d”,sm);
[Ch#12] Loop Constructors 362 Computer Science Part-II
}
Q8. Print the table of any number using for loop
Answer:
#include<stdio.h>
void main ( )
{
int n,c;
printf(“\n Enter table Number “);
scanf(“%d”, &n);
for(c=1;c<=10;c++)
{
printf(“\n %d x %d = %d”, n, c , n*c);
}
}
Q9. Print the table of any number using while loop
Answer:
#include<stdio.h>
void main ( )
{
int n,c;
printf(“\n Enter table Number “);
scanf(“%d”, &n);
c=1;
while(c<=10)
{
printf(“\n %d x %d = %d”, n, c ,n*c);
c++;
}
}
Q10. Print the Table using do-while loop
Answer:
#include<stdio.h>
void main ( )
{
int n, c;
[Ch#12] Loop Constructors 363 Computer Science Part-II
printf(“\n Enter table Number “);
[Ch#12] Loop Constructors 364 Computer Science Part-II

scanf(“%d”, &n);
c=1;
do
{
printf(“\n %d x %d = %d”, n , c, n*c);
c++;
}
while(c<=10);
}
Q11. Print the factorial of a number using do while
Answer:
#include<stdio.h>
void main ( )
{
int n,c=1;
printf(“\n Enter any Number 0 to 7 “);
scanf(“%d”, &n);
do
{
c=c*n;
n--;
}
while(n>=1);
printf(“\n The Factorial of given number = %d “, c);
}
Q12. Print the factorial of a number using for loop
Answer:
#include<stdio.h>
void main ( )
{
[Ch#12] Loop Constructors 365 Computer Science Part-II

int n,c=1,k;
printf(“\n Enter any Number 0 to 7 “);
scanf(“%d”, &n);
for(k=n;k>=1;k--)
{
c=c*k;
}
printf(“\n The Factorial of given number = %d “, c);
}
Q13. Trace the output of the program:
Answer:
Program Output ( � denotes blank spaces)
k=0; loop iteration = 6
while(k<=5) ( k=0,1,2,3,4,5)
{ k=0 ; output � �0 � 10
printf(“%3d%3d\n”, k , 10-k); k=1 ; output � �1 � �9
k++; k=2 ; output � �2 � �8
}
k=3 ; output � �3 � �7
k=4 ; output � �4 � �6
k=5 ; output � �5 � �5
Q14. Trace the output of the program
Answer:
Program Output ( _ denotes blank spaces)
j=10; loop iteration = 5
for(int i=1;i<=5; + + i) (i=,1,2,3,4,5)
{ i=1 ; output 1 _ 10
printf(“%d %d\n”, i, j); i=2 ; output 2 _ 8
j - = 2; i=3 ; output 3 _ 6
} i=4 ; output 4 _ 4
i=5 ; output 5 _ 2
[Ch#12] Loop Constructors 366 Computer Science Part-II
Q15. Trace the output of the program assuming m=3,n=5
Answer:
Program Output
for(k=1;k<=n; ++k) *
{ **
for(j=0; j<k; ++j) ***
{ ****
printf(“*”); *****
}
printf(“\n”);
}
Q16. Trace the output of the program assuming m=3,n=5
Answer:
Program Output
for(k=n;k>=0; --k) ***
{ ***
for(j=m; j>0; --j) ***
{ ***
printf(“*”); ***
}
printf(“\n”);
}
Q17. Correct the following code according to the instructions: Insert braces where
they are needed and correct errors if any. The corrected code should accept
five integers and should display their sum.
Answer:
incorrect code correct code
count = 0; int count=0, sum=0, next_num;
while(count<=5); count = 0;
count += 1; while(count<=5)
printf(“next number >”); {
scanf(“%d”, &next_num); count += 1;
next_num += sum; printf(“next number >”);
printf(“%d numbers were added; \n”); scanf(“%d”, &next_num);
printf(“their sum is %d. \n”, sum); sum += next_num;
}
printf(“%d numbers were added; \n”,
count);
[Ch#12] Loop Constructors 367 Computer Science Part-II
printf(“their sum is %d. \n”, sum);
Q18. Rewrite the following code segment using do-while loop.
Answer:
Code with do-while statement
sum=0; int sum=0,odd=1;
for(odd = 1; odd<n; odd = odd+2) do
sum = sum + odd; {
printf(“sum of the positive odd numbers less sum = sum + odd;
than %d is %d\n”,n, sum); odd = odd+2;
}
while(odd<=n);
printf(“sum of the positive odd numbers less
than %d is %d\n”,n, sum);
Q19. Prime Number
Answer:
#include<stdio.h>
void main ( )
{
int n, k;
printf(“\n Enter any Number :>>>> “);
scanf(“%d”, &n);
k=2;
while (k<=n-1)
{
if(n%k==0)
{
printf(“\n %d is not A Prime Number “, n);
break;
}
k++;
}
if (k == n)
[Ch#12] Loop Constructors 368 Computer Science Part-II
printf(“\n The Number is prime = %d “, n);
}
Q20. Print first 10 Natural Numbers, their squares and their cubes and calculate
the sum of these three series using for loop.
S1=1+2+3+-----+10, S2=12+22+32+-----+102, S3=13+23+33+-----+103
Answer:
#include<stdio.h>
void main( )
{
int i, s1=0,s2=0,s3=0;
for(i=1;i<=10;i++)
{
printf(“\n %d \t %d \t %d”,i,i*i,i*i*i);
s1=s1+I;
s2 = s2 + (i*i);
s3 = s2 + (i*i*i);
}
printf(“\ns1= %d \t s2=%d \t s3=%d”, s1,s2,s3);
}
Q21. Write a program that produces the following output
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
0 1 2 3 4 5
Answer:
#include<stdio.h>
void main ( )
{
int i, j;
for (j=0;j<=5;j++)
{
for(i=0;i<=j;i++)
printf(“%d\t”,i);
[Ch#12] Loop Constructors 369 Computer Science Part-II
printf(“\n”);
}
}
Q22. Write a program that produces the following output
0 1
1 2
2 4
3 8
4 16
5 32
6 64
Answer:
#include<stdio.h>
#include<math.h>
void main ( )
{
float j;
for (j=0;j<=6;j++)
printf(“\n%4.0f\t\t%4.0f”, j, pow(2,j) );
}
OR
#include<stdio.h>
void main ( )
{
int j, i = 1;
for (j=0;j<=6;j++)
{
printf(“\n%d\t%d”, j, i);
i *= 2;
}
}
Q23. Input and output of an array using scanf( )
Answer:
#include<stdio.h>
void main( )
{
int a[5],i;
for(i=0;i<=4;i++)
{
printf(“\n Enter Array Element ”);
scanf(“%d”, &a[i]);
[Ch#12] Loop Constructors 370 Computer Science Part-II
}
for(i=0;i<=4;i++)
printf(“\n Array Element at %d index = %d ”,i, a[i]);
}
Q24. Input array elements and calculate sum
Answer:
#include<stdio.h>
void main( )
{
int a[5],i, s=0;
for(i=0;i<=4;i++)
{
printf(“\n Enter Array Element ”);
scanf(“%d”, &a[i]);
s += a[i];
}
printf(“\n Sum of all Array Elements = %d ”, s);
}
Q25. Input array elements and sorting of an array.
Answer:
#include<stdio.h>
void main( )
{
int a[5], i, temp, j;
for(i=0;i<=4;i++)
{
printf(“\n Enter Array Element ”);
scanf(“%d”, &a[i]);
}
for(i=1;i<=4;i++)
for(j=0;j<=3;j++)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
[Ch#12] Loop Constructors 371 Computer Science Part-II
}
for(i=0;i<=4;i++)
printf(“\n Array Elements in order are : %d”, a[i]);
}
Q26. Input array elements and find largest number in an array.
Answer:
#include<stdio.h>
void main( )
{
int a[5], i, max;
for(i=0;i<=4;i++)
{
printf(“\n Enter Array Element”);
scanf(“%d”, &a[i]);
}
max = a[0];
for(i=1;i<=4;i++)
if(a[i]>max)
max=a[i];
printf(“\n Largest Number in Array Elements = %d ”, max);
}
Q27. Input array elements and find smallest number in an array.
Answer:
#include<stdio.h>
void main( )
{
int a[5], i, min;
for(i=0;i<=4;i++)
{
printf(“\n Enter Array Element”);
scanf(“%d”, &a[i]);
}
min=a[0];
for(i=1;i<=4;i++)
if(a[i]<min)
min=a[i];
[Ch#12] Loop Constructors 372 Computer Science Part-II
printf(“\n Smallest Number in Array Elements = %d ”, min);
}
[Ch#13] Functions 380 Computer Science Part-II

Q.1 Fill in the blanks:


1. A function is a self contained piece of code.
2. Pre-defined functions are packaged in libraries.
3. A prototype provides basic information about the function to the compiler.
4. The duration for which a variable exists in memory is called its lifetime.
5. Scope of a variable refers to the region of the program where it can be referenced.
6. Global variables are declared outside all blocks.
7. A function can not return more than one value (s) through return statement.
8. The parameters specified in the function header are called formal parameters.
9. The parameters passed to a function in the function call are called actual
parameters.
10. Functions help to achieve modular programming.
Q.2 Choose the correct option:
1. Functions prototype for built-in functions are specified in:
a) source files b) header files
c) object files d) image files
2. Global variables are created in
a) RAM b) ROM
c) Hard Disk d) cache
3. Which of the following is true about a function call?
a) Stops the execution of the program.
b) Transfers control to the called function.
c) Transfers control to the main function.
d) Resumes the execution of the program.
4. The predefined functions that are part of C-language are called:
(a) user-defined (b) subprograms
(c) subroutines (d) built-in functions
5. The functions that are defined by programmer are called:
(a) user-defined (b) subprograms
[Ch#13] Functions 381 Computer Science Part-II
(c) subroutines (d) built-in functions
6. Another name for built-in function is:
(a) user-defined function (b) library function
(c) ready-made function (d) None
7. A function is called with the reference of its:
(a) name (b) parameter
(c) definition (d) None
8. A function:
(a) may return more than one values.
(b) may return only one value.
(c) cannot return any value. (d) None of these
9. The actual values are passed to the function in:
(a) function declaration (b) function call
(c) function definition (d) All
10. Which of the following looks for the prototype of functions used in a program:
a) linker b) loader
c) compiler d) parser
11. The name of actual and formal parameters:
a) May or may not be same b) Must be same
c) Must be different d) Must be in lowercase
12. Formal arguments are also called
a) Actual arguments b) Dummy arguments
c) Original arguments d) Referenced arguments
13. The printf() is a:
a) Built-in function b) User defined function
c) Local function d) keyword
14. The actual body of the function is defined in:
(a) function declaration (b) function call
(c) function definition (d) None
15. The last statement of the body of the function is:
(a) break; (b) continue;
(c) return (d) shift
16. A built-in function:
a) Can not be redefined b) Can be redefined
[Ch#13] Functions 382 Computer Science Part-II
c) Can not return a value d) Should be redefined
17. In a C program two functions can have:
a) Same name b) Same parameters
c) Same name and same parameters d) Same name but different parameters
18. The name of actual and formal parameters:
(a) may or may not be same (b) must be same
(c) must be different (d) must be in lowercase
19. In C-language, subprograms are referred to as:
(a) Methods (b) Procedure
(c) functions (d) modules
20. The predefined functions that are part of the programming language and can be
used for different purposes are called:
(a) Library functions (b) Built-in functions
(c) user-defined functions (d) Both a & b
21. The parameters specified in the function header are called:
(a) formal parameters (b) actual parameters
(c) default parameters (d) command line parameters
22. __________ perform tasks that may need to be repeated many times.
a) Condition b) Module
c) Program d) Function
23. If the whole logic of program is contained in main function, it is called
____________.
a) Structured Programming b) Un structured Programming
c) Object Oriented Programming d) Modular Programming
24. Built in functions make our task ____________.
a) Complex b) Lengthy
c) Simple d) Technical
25. The parameters passed to a function in the function call are called:
(a) formal parameters (b) actual parameters
(c) default parameters (d) command line parameters
26. Which of the following is the advantage of function?
(a) Easy to write program (b) Eliminate duplicate code
(c) Re-usability (d) All of these
27. Function definition consists of:
(a) function header (b) Function body
[Ch#13] Functions 383 Computer Science Part-II
(c) Both a & b (d) None
28. The first line of function definition is called _________.
a) Function Face b) Function Definition
c) Function Header d) Function Name
29. The region of a program in which a variable is accessible, refers to its
a) Area b) Scope
c) Function d) Use
30. As soon as the control moves outside of their scope, local variable are
a) Need to declare again b) Accessible to only a limited set of instructions
c) Accessible d) Destroyed
31. Function declaration consists of:
(a) function name
(b) Function return type
(c) number and types of parameters
(d) All
32. What is true about a function prototype?
(a) It is also referred to as function declaration
(b) It is terminated with a semicolon (;)
(c) It is a single statement.
(d) All of these
33. A function that does not return anything has return type:
(a) nothing (b) float
(c) void (d) null
34. The variables that are declared outside all blocks is called
a) General Variables b) Variables
c) Global variables d) Global Data Items
35. What is the return type of the function with prototype: “int func(char x, float v,
double t );”
a) char b) double
c) float d) int
36. The function declaration statement int abc (void); indicates that:
(a) Return data type of function is void.
(b) return data type of function is int.
(c) function take no argument.
(d) function takes one argument of int type.
[Ch#13] Functions 384 Computer Science Part-II
(e) Both (b) and (c)
37. The variables declared inside any function are known as:
(a) global variable (b) private variable
(c) external variable (d) local variable
38. Which of the following is a valid function call (assuming the function exists)?
a) funct; b) funct x,y;
c) funct(); d) int funct();
39. Which of the following can return a value?
a) Function b) Procedure
c) Both a and b d) None of Above
40. Data can be shared between functions using:
(a) local variable (b) static variable
(c) global variable (d) register variable
41. Local variables are also called:
(a) Automatic (b) Normal
(c) Global (d) None
Q.3 Write T for True and F for false Statements.

1. In C arguments can be passed to a function by value (T)

2. There can be multiple main functions in a C program (F)

3. A function can be called anywhere in the program (T)

4. In C, every function must return a value (F)

5. A user defined function can not be called in another user defined (F)
function.

6. A function can be called only once in a program (F)

7. Scope of a local variable is the block in which it is defined. (T)

8. Global variables exist in memory till the execution of the program. (T)

9. An unstructured program is more difficult to debug than a structured (T)


program.
[Ch#13] Functions 385 Computer Science Part-II

10. Function body is an optional part of the function. (F)


Q4. Write a program that call two functions draw_horizontal and draw_vertical
to construct a rectangle. Also write functions draw_horizontal to draw
parallel horizontal lines and draw_vertical to draw parallel vertical lines.
Answer:
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void draw_horizontal (int x, int y, int w, int h);
void draw_vertical (int x, int y, int w, int h);
void main( )
{
int x, y, w, h;
int gdriver=DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode,”c:\\tc\\bgi”);
printf(“\n Enter Width “);
scanf(“%d”, &w);
printf(“\n Enter Height “);
scanf(“%d”, &h);
printf(“\n Enter X Value “);
scanf(“%d”, &x);
printf(“\n Enter Y Value “);
scanf(“%d”, &y);
draw_horizontal (x, y, w, h);
draw_vertical (x, y, w, h);
}
void draw_horizontal (int x, int y, int w, int h)
{
line (x, y, x + w, y);
line (x, y + h, x + w, y + h);
}
void draw_vertical (int x, int y, int w, int h)
{
line (x, y, x , y + h);
[Ch#13] Functions 386 Computer Science Part-II
line (x + w, y, x + w, y + h);
}
Q5. Write a program that gets two points (x1, y1) and (x2, y2). Displays the
distance between them using distance formula in a function.
Answer:
#include<stdio.h>
#include<math.h>
float distance(float, float, float, float);
void main( )
{
float x1, x2, y1, y2, d;
printf(“\n Enter Co-ordinates of First Point x1 and y1”);
scanf(“%f %f”, &x1, &y1);
printf(“\n Enter Co-ordinates of Second Point x2 and y2”);
scanf(“%f %f”, &x2, &y2);
d = distance(x1, y1, x2, y2);
printf(“\n Distance Between Two Points = %.2f”, d);
}
float distance(float x1, float y1, float x2, float y2)
{
float dis, x, y;
x = x2 - x1;
y = y2 - y1
dis = sqrt(x*x + y*y);
return dis;
}
Q6. Write a program hat prompts the user to enter a number and then reverse it
through function.
Answer:
#include<stdio.h>
int reverse(int);
void main( )
[Ch#13] Functions 387 Computer Science Part-II
{
int n, rvrs;
printf(“\n Enter 4 digit Number”);
scanf(“%d” , &n);
rvrs = reverse(n);
printf(“\n Reverse Number = %d”, rvrs);
}
int reverse(int n) //1234
{
int a, b, c, d, e, f, rvrs;
a = n/1000; //a=1
b = n%1000; //b=234
c = b/100; //c=2
d = b%100; //d=34
e = d/10; //e=3
f = d%10; //f=4
rvrs = f*1000 + e*100 + c*10 + a;
return rvrs;
}
Q7. Produce the following output using draw_astrisk function
*******
******
*****
****
***
**
*
Answer:
#include<stdio.h>
void draw_astrisk(void);
void main()
{
draw_astrisk();
[Ch#13] Functions 388 Computer Science Part-II
}
void draw_astrisk(void)
{
int r, c;
for (c=7;c>=1; c--)
{
for (r=1;r<=c;r++)
{
printf(“*”);
}
printf(“\n”);
}
}
Q8. Write a function isPrime that input a number and return 1 if number is
prime otherwise return 0.
Answer:
#include<stdio.h>
int isPrime(int);
void main()
{
int n, res;
printf(“\n Enter any Number : “);
scanf(“%d”, &n);
res = isPrime(n);
if(res==1)
printf(“\n Number is prime and returned value is 1”);
else
printf(“\n Number is Not prime and returned value is 0”);
}
int isPrime(int n)
{
int k =2;
while (k<=n-1)
{
if(n%k==0)
return 0;
else
[Ch#13] Functions 389 Computer Science Part-II
k++;
}
return 1;
}
Q9. Perform arithmetic operations using functions
Answer:
#include<stdio.h>
float add(float,float);
float sub(float,float);
float mul(float,float);
float div(float,float);
void main ( )
{
float a,b, res;
int op;
printf(“\n Enter two Numbers : “);
scanf(“%f %f”, &a,&b);
printf(“\n Enter 1 for Addition : “);
printf(“\n Enter 2 for Subtraction : “);
printf(“\n Enter 3 for Multiplication : “);
printf(“\n Enter 4 for Division : “);
printf(“\n Now please press 1 2 3 or 4 : “);
scanf(“%d”, &op);
switch(op)
{
case 1:
res=add(a,b);
break;
case 2:
res=sub(a,b);
break;
case 3:
res=mul(a,b);
break;
[Ch#13] Functions 390 Computer Science Part-II
case 4:
res=div(a,b);
break;
default:
printf(“ Choice is invalid “);
}
printf(“\n Result = %.2f”,res);
}
float add(float x, float y)
{
return x+y;
}
float sub(float x, float y)
{
return x-y;
}
float mul(float x,float y)
{
return x*y;
}
float div(float x, float y)
{
if (x==0 || y ==0 )
{
printf(“\n Do Not Use Zero in Division”);
return 0;
}
if(x>y)
return x/y;
else
return y/x;
}
Q10. Program of Factorial using function:
Answer:
#include<stdio.h>
int fact(int);
void main()
[Ch#13] Functions 391 Computer Science Part-II
{
int n, res;
printf(“\n Enter any Number range [1-7] : “);
scanf(“%d”, &n);
res = fact(n);
printf(“\n Factorial of %d is %d”, n, res);
}
int fact(int n)
{
int a=1,i;
for(i=1; i<=n; i++)
a *= i;
return a;
}
Q11. Calculate GCD of two Numbers through function:
Answer:
#include<stdio.h>
int gcd(int, int);
void main()
{
int a,b, res;
printf(“\n Enter Two Positive Numbers: “);
scanf(“%d %d”, &a, &b);
res = gcd(a,b);
printf(“\n GCD = %d”, res);
}
int gcd(int a, int b)
{
int gcd, r, tmp;
c: r=a%b;
if(r==0)
gcd=b;
else
{
a=b;
[Ch#13] Functions 392 Computer Science Part-II
b=r;
goto c;
}
return gcd;
}
[Ch#14] File Handling in C 410 Computer Science Part-II

Q.1 Fill in the blanks.


1. A text file can store text only.
2. EOF stands for end of file.
3. The fopen function is used to open a file.
4. An open file must be closed before terminating the program.
5. A file opened in a+ mode can be read and appended.
6. A file pointer is a variable of type FILE*.
7. A pointer is a memory location whose contents point to another another memory
location.
8. In C every valid string ends with null character.
9. A string is an array of characters.
10. The fopen( ) returns a NULL if it fails to open a file for some reason.
Q.2 Choose the correct option:
1. A file is stored in:
a) RAM b) Hard Disk
c) ROM d) Cache
2. Which of the following function is used to write a string to a file?
a) puts( ) b) pute( )
c) fputs( ) d) fgets( )
3. On successfully closing a file , the fclose( ) returns:
a) NULL b) 0
c) 1 d) file pointer
4. An array subscript should be
a) int b) float
c) double d) an array
5. A data file a stored in:
(a) RAM (b) hard disk
(c) EEPROM (d) None
[Ch#14] File Handling in C 411 Computer Science Part-II
6. Which of the following mode open only an existing file for both reading and
writing?
(a) “w” (b) “w+”
(c) “r+” (d) “a+”
7.  function is used to write a string to a file:
(a) puts() (b) putc()
(c) fputs() (d) fgets()
8. To store data for future use it must be stored on _____________
a) RAM b) ROM
c) Secondary Storage d) All of Above
9. A collection of related records is called __________
a) Data b) Field
c) Database d) File
10. A logical interface to a file is called ____________.
a) I/O b) File I/O
c) Stream d) Pointer
11. A stream is associated with a file using and ________operaton
a) Association b) Attach
c) Link d) Open
12.  function is used to read a single character from a file at a time:
(a) fscanf() (b) getch()
(c) fgetc() (d) fgetc()
13.  function is used as formatted output file function:
(a) printf() (b) fprintf()
(c) puts() (d) fputs()
14. If programs get input data from data file and also send output into data file. It is
called:
(a) files (b) file processing
(c) data files (d) file handling
15. There are ___ types of streams
a) 1 b) 2
c) 3 d) Many
[Ch#14] File Handling in C 412 Computer Science Part-II
16. In file handling sequence of characters refers to __________
a) Text Stream b) File Stream
c) Binary Stream d) Character Stream
17. In text stream characters have _________ correspondence
a) One to One b) One to Many
c) Many to One d) All of above
18. In binary stream bytes have ______________correspondence
a) One to one b) One to Many
c) Many to One d) All of Above
19. In text file, data is stored in:
(a) ASCII code (b) Binary code
(c) Octal code (d) text code
20.  is true about a stream:
(a) It is a general name given to a flow of data
(b) It is simply a sequence of bytes.
(c) It is a logical interface to data files.
(d) All of these
21. In  character conversion
(a) text stream (b) binary stream
(c) output stream (d) input stream
22. In file handling sequence of bytes refers to __________
a) Text Stream b) File Stream
c) Binary Stream d) Character Stream
23. A text file is a _________ collection of characters
a) Fresh b) Old
c) Named d) All of Above
24. To mention end of file point a marker______ is used
a) File End (FE) b) End File(EF)
c) End of File(EF) d) End of File(EOF)
25. To open a file __________ function is used
a) open() b) fileopen()
c) fopen() d) All of Abvoe
[Ch#14] File Handling in C 413 Computer Science Part-II
26.  represents the new-line marker:
(a) ‘\t’ (b) ‘\n’
(c) ‘\r’ (d) ‘\0’
27. The data type of file pointer is:
(a) int (b) double
(c) void (d) FILE
28.  mode can be used to read data from the data file:
(a) “r” (b) “a”
(c) “w” (d) None
29.  modes can be used to read and write data to and from the data file:
(a) “r+” (b) “a+”
(c) “w+” (d) All of these
30. fopen() function take _____ parameters
a) 1 b) 2
c) 3 d) 4
31. In the absolute path of a file we use_______
a) / b) \
c) \\ d) //
32. To open a file for writing if it already exists
a) W b) r+
c) r d) read
33. Which one is true about pointer type variable
a) It holds the data
b) It holds the information
c) It holds the address of a memory location
d) It hold the name of a location
34. Which of the following is ca consecutive group of memory locations with the
same name and type?
(a) Simple variable (b) Structure
(c) Array (d) Pointer
[Ch#14] File Handling in C 414 Computer Science Part-II
35. An array index / subscript must be of data type:
(a) int (b) double
(c) float (d) All of these
36. A file can be closed using _________ funciton
a) close() b) fclose()
c) fileclose() d) None of Above
37. To write a character on a file ________ function is used
a) write() b) fwrite()
c) put() d) putc()
38. To write a character on a file function takes ________ parameters
a) 0 b) 1
c) 2 d) 3
39. The index of an element is written within:
(a) curly brackets { } (b) parentheses ( )
(c) square breakles [ ] (d) angle brackets < >
40. The elements of array abc [10] is numbered from:
(a) 1 to 10 (b) −5 to 5
(c) 0 to 9 (d) 0 to 10
41.  assignment statements assigns value to the first element of an array a:
(a) a = 15; (b) a[0] = 15;
(c) a [1] = 15; (d) All of these
42. Which one is not a valid parameter of putc() function
a) File Name b) Character
c) File Pointer d) All of Above
Q.3 Write T for True and F for false Statements.
1. A picture can not be stored in a text file (T)
2. EOF marks the end of string (F)
3. A null character marks the end of text file (F)
4. Text files are stored in FILE* (F)
5. The name of the array points to its first element (T)
6. Array subscript is used to access array elements (T)
7. An array of characters can store data of any data type (F)
8. A binary file is a group of contiguous memory locations (F)
9. C can handle text files only (F)
10. When an existing file is opened in w mode, its contents are over-written. (T)
[Ch#14] File Handling in C 415 Computer Science Part-II
Q4. Write a program that merges the contents of two text files.
Answer:
#include<stdio.h>
#include<conio.h>
void main( )
{
FILE *sf, *df;
char ch, sfl[20], dfl[20];
clrscr();
printf(“\n Enter Name of file to READ DATA >>”;
scanf(“%s”, &sfl);
printf(“\n Enter Name of file to MERGE DATA >>”;
scanf(“%s”, &dfl);
sf = fopen(sfl, "r");
df=fopen(dfl, “a”);
if(sf = = NULL) printf(“File Does Not exist or file error ”);
while(ch=fgets(sf)!=EOF)
{
fputs(ch, df);
}
printf(“\n Data is copied from source to destination “);
fclose(sf);
fclose(df);
}
Q5. Write a program that counts the total number of characters in a file.
Answer:
#include<stdio.h>
#include<conio.h>
void main( )
{
FILE *sf ;
char ch, sfl[20];
int cnt=0;
clrscr();
[Ch#14] File Handling in C 416 Computer Science Part-II
printf(“\n Enter Name of file to READ DATA >>”;
scanf(“%s”, &sfl);
sf = fopen(sfl, "r");
if(sf = = NULL) printf(“File Does Not exist or file error ”);
while(ch=fgets(sf)!=EOF)
{
printf(“%c”, ch);
cnt++;
}
printf(“\n Total Characters in a file are = %d”, cnt);
fclose(sf);
getch( );
}
Q6. Write a program that counts the total number of words in a file.
Answer:
#include<stdio.h>
#include<conio.h>
void main( )
{
FILE *sf ;
char ch, sfl[20], last;
int spc=0;
clrscr();
printf(“\n Enter Name of file to READ DATA >>”;
scanf(“%s”, &sfl);
sf = fopen(sfl, "r");
if(sf = = NULL) printf(“File Does Not exist or file error ”);
while(ch=fgetc(sf)!=EOF)
{
if(ch == ‘ ‘)
if(!(last == ‘ ‘))
spc++;
last = ch;
}
printf(“\n Total WORDS in a file are = %d”, spc + 1);
fclose(sf);
getch( );
}

You might also like