VINAYAKA MISSION’S RESEARCH FOUNDATION
SCHOOL OF ARTS AND SCIENCE
DEPARTMENT OF COMPUTER SCIENCE
Semester: Even AY: 2024-2025
Assessment: IAT - I DoE: 19/02/2025
Subject: BCA, CC-II, PROGRAMMING IN C Code: 71721201
Duration: 2 Hrs. Max. Marks: 50
Faculty In charge: Dr. Srinivasan Balasubramanian Designation: Associate Professor
Answer Key
Questions
PART A (5 x 2 = 10 marks)
Q. NO. Answer ALL questions Marks
All questions carry equal marks
1 Programming is the way of instructing the computer to solve a given problem with the 2
help of programs.
2 Programs are developed to process data and solve a problem quickly without the help of 2
human processing.
3 2
4 Keywords are pre-defined words that exist in a programming language and define a 2
special meaning within the used programs.
5 Constant is a term within programming which will never changes its value during the 2
execution of a program.
PART B (5 x 4 = 20 marks)
Q. NO. Answer Any Four questions Marks
All questions carry equal marks
6 (a) Importance of C language: 5
Robust: The C language is robust, containing at least 32 keywords and
a rich set of built-in library supports. Programs written in C language can
run on any machine with different hardware environments.
Faster: Programs written in C are efficient and many times faster than
other programming languages. For example, a program to increment a
variable from 0 to 15000 takes about one second in C, but in other
languages like BASIC, it takes more than 50 seconds.
Portable: Programs written in C languages are very portable, meaning
that programs made in C for one computer can efficiently run on another
with little or no modification.
Structured: The C language supports structured programming, which
means that the program for the entire given problem will be split into
many subprograms called functions. A main part of the C program, the
main() function, will integrate all the sub-functions.
Extended: The essential feature of C programming is extensibility, which
means adding functionality with a richer set of libraries. Programs
developed by programmers can also be added to C libraries, so
functionality developed by one can be further extended to all.
(OR)
6 (b) Built-in tokens are predefined keywords and symbols with special meanings. They 5
define the structure and syntax of a C program.
Keywords are built-in tokens that have a pre-defined meaning during program execution.
In C language, a keyword is a statement or function name. For example, "main" indicates
the main part of any C program.
Constants are values or literals that will never change during the execution of a C
program.
Strings are a sequence of characters defining non-numerical values such as the names of
students, employees, or product names within a C program. Strings are given within
double quotes.
Operators are built-in tokens that define arithmetic, logical, and relational operations to
be carried out within a C program. An operator can operate over a single or two operands
and produce results.
Special Symbols or Special Characters are built-in tokens that have a predefined
meaning within a C program. For example, should the delimiter be placed at the end of
every statement in a C program?
7 (a) Rules for defining variables 5
1. A variable might be a single character or collection of strings
2. Variables should be declared before they are going to be used in a C program
3. The maximum length of a variable is 32
4. Variables should not contain any special character except _(underscore)
5. The first character of a variable is always a character or _.
(OR)
7 (b) Programming is an art rather than a learning process. Once a problem is given to a 5
programmer or a learner of a programming language, they should consider a key point by
remembering how to solve the problem manually before coding. Once they have manual
ideas, they can quickly turn them into steps for writing programs.
The planned ideas are converted into easy steps called algorithms and are also
represented by using a diagram called a flow chart.
Definition of Algorithm:
An algorithm is a step-by-step procedure for solving a problem or performing a
task. It takes input, processes it, and produces output.
Definition of Flow Chart:
A flowchart is a graphical representation of an algorithm or process showing the
sequence of steps and the control flow. It uses symbols, arrows, and text to illustrate the
logic and steps involved.
8 (a) #include <stdio.h> 5
void main() {
printf("Welcome to C");
}
The first line indicates the include section and the header file called standard input and
output <stdio.h> is included. The next line contains void main() indicating the starting
point of the C program. The main program is also called as main() funciotn and contains
printf() function with the string “Welcome to C”. The execution part of this C program is
given in between open and close curly braces. Once the program is run on a computer, it
simply prints the word “Welcome to C”.
(OR)
8 (b) Operators in C are used to perform various operations. There are different types of 5
operators:
Arithmetic operators (+, -, *, /, %) are used for doing arithmetic processing.
Relational operators (==, !=, >, <, >=, <=) are used for comparing values.
Logical operators (&&, ||, !) are used for making logical decisions.
Assignment operators (=, +=, -=, *=, /=, %=) are used for assigning values.
Bitwise operators (&, |, ^, ~, <<, >>) are used for performing bit-level operations.
Increment/Decrement operators (++ , --) are used for incrementing/decrementing values.
Arithmetic expressions in C are combinations of variables, constants, and arithmetic
operators that evaluate to a single value. These expressions perform mathematical
operations such as addition, subtraction, multiplication, and division.
Arithmetic operators in C include unary operators (+, -), binary operators (+, -, *, /, %),
and parentheses to group expressions. The order of evaluation is determined by the
9 (a) 5
precedence of operators, with parentheses evaluated first, followed by unary operators,
multiplication and division, and finally, addition and subtraction.
Arithmetic expressions are used extensively in C programming to perform calculations,
assign values to variables, and control the flow of programs. They are a fundamental
concept in programming and are used to solve a wide range of problems.
(OR)
Conditional statements in C execute different blocks of code based on certain conditions.
The types of conditional statements are:
1. If statement: Used to execute a code block if a condition is true.
Example: if (x > 10) printf("x is greater than 10");
2. If-else statement: Used to execute one block of code if a condition is true and another
9 (b) block if the condition is false. 5
Example: if (x > 10) printf("x is greater than 10"); else printf("x is less than or equal to
10");
3. Switch statement: Used to execute different blocks of code based on the value of a
variable.
Example: switch (x) {case 1: printf("x is 1"); break; case 2: printf("x is 2"); break;}
Q. NO. PART B (2 x 10 = 20 marks) Marks
Answer Any Two questions
All questions carry equal marks
10 Basic Structure of a C Program 10
A program written in C language contains many compulsory and optional parts.
Basically, a C program is divided into several subsections, and each section plays its role
during the program's execution. Typically, a C program comprises six sections, as shown
in the following diagram.
Documentation Section: The documentation Section contains a set of
comment lines explaining the name or purpose of a C program, the author's name,
the written date, and other details. This section is only used for future reference
purposes and also contains the non-executable part of C programs.
Link Section: The link section contains the # include directive, which instructs
the compiler to include runtime libraries, header files, and already-written C
programs.
Definition Section: The Definition section of a C program defines all symbolic
constants and Macro definitions.
Global Declaration Section: Some variables are used by more than one function.
Such variables are declared in this section. This section also declares all user-
defined functions.
main () function section: Every C program must contain a compulsory main()
function section. The main function must start with the keyword main() and have
two parts: declaration and execution.
The declaration part declares all the local variables used within the main function.
The executable part contains statements and function calls executed at a C
program's runtime. There should be at least one executable statement in the
execution part of any C program.
Both Declaration and execution parts must appear in between opening and
closing curly braces ({,}). The program execution begins at the opening of the
curly brace and ends at the closing of the curly brace. All statements in the
executable part of a C program must end with (a semicolon) and act as the
delimiter, indicating the end of a line in the C program.
Subprogram Section: The subprogram section contains all the user-defined
functions definition parts that are called in the main () function section. In C
programming all user-defined functions are immediately be placed after the
main() function , even they may appear in any order.
In a C program all the sections except the main() function section are optional , and are
defined based on the needs.
Sample Program
/* Program to Print PI value */
#include <stdio.h>
#define PI 3.14
Int radius=5;/* global variable */
main()
{
int area=0;
area=calculatearea(radius);
printf(“area of the circle=%.2f”,area);
}
calculatearea(radius)
{
Return (PI * radius * radius);
}
11 C provides various numerical data types, enabling programmers to express many sorts 10
of numbers with differing accuracy and range. These may be classified into integer and
floating-point categories.
1. Integer Data Types:
Integer types denote full integers, including positive and negative values, as well as zero.
C has many integer types, largely distinguished by their memory allocation, which
therefore influences the range of values they can accommodate.
int: The predominant integer type. The size is implementation-defined, however it is
generally 4 bytes (32 bits) on most contemporary systems. It provides an optimal
equilibrium between range and memory consumption. It can accommodate numbers
approximately ranging from -2,147,483,648 to 2,147,483,647.
Although predominantly used for denoting characters (ASCII values), char is, in fact, an
integer type. It generally occupies 1 byte (8 bits) of memory. It can accommodate values
ranging from -128 to 127 (signed char) or from 0 to 255 (unsigned char). It is
advantageous for tiny integers or when memory economy is critical.
Short int (or just short): Typically, smaller than int, sometimes using 2 bytes (16 bits). It
provides a narrower range than int, often from -32,768 to 32,767. It is advantageous
when memory is limited.
Long int (or just long): Typically, bigger than int, sometimes using 4 or 8 bytes. It offers
an expanded spectrum of values. The precise dimensions are contingent upon the
compiler and system architecture.
long long int (or simply long long): Guaranteed to have a minimum size of 8 bytes (64
bits). It provides the most extensive range among integer types.
Unsigned Integer Types: Each signed integer type referenced above has a corresponding
unsigned variant (e.g., unsigned int, unsigned char, unsigned short, unsigned long,
unsigned long long). Unsigned types only allow non-negative values, thereby doubling
the positive range relative to their signed equivalents, since they do not allocate a bit for
the sign. For example, unsigned int can typically store values from 0 to 4,294,967,295.
2. Floating-Point Data Types:
Floating-point types represent numbers that have fractional components (real numbers).
C provides three primary floating-point types:
Float: A single-precision floating-point data type, often using 4 bytes (32 bits). It
provides an equitable balance between accuracy and range. It is appropriate for the
majority of general-purpose floating-point computations.
Double: A double-precision floating-point data type, often using 8 bytes (64 bits). It
offers greater accuracy and an expanded range compared to float. It is often the standard
option for floating-point computations where accuracy is paramount.
Long double: An extended-precision floating-point type, often containing 10 or 16 bytes.
It provides superior accuracy and range compared to double. It is used when exceptional
accuracy is necessary.
int age = 25; // Integer for age
float height = 5.8; // Floating-point for height
double pi = 3.14159265359; // Double for pi (more precision)
char initial = 'J'; // Character for initial
unsigned int count = 100; // Unsigned integer for a count
12 Loop Constructs in C 10
Loop statements in C allow the repeated execution of a code block while a specified
condition remains true. C has three primary categories of loop statements: for, while, and
do-while. Every loop type has distinct syntax and applications.
1. For Loop:
The for loop is often used when the number of iterations is predetermined or can be
readily computed. It comprises three components inside the parentheses:
Initialization: This segment is run just once at the commencement of the loop. It is often
used to establish a loop counter variable.
Condition: This component is assessed before to each repetition. Upon the condition
being true, the loop body is performed. If it is false, the loop ends.
Increment/Decrement (Update): This section is run subsequent to each iteration. It is
often used to modify the loop counter variable.
for (initialization; condition; update) {
// Loop body (code to be executed repeatedly)}
for (int i = 0; i < 10; i++) {
printf("Value of i: %d\n", i);
}
2.while loop
The while loop is used when the iteration count is indeterminate beforehand and is
contingent upon a condition that may fluctuate during the loop's execution. The
condition is assessed before to each repetition. Upon the condition being true, the loop
body is performed. If it is false, the loop ends.
Syntax
while (condition) { // Loop body (code to be executed iteratively) }
Illustration:
Example
int i = 0; while (i < 10) printf("Value of i: %d\n", i); i++;
This one is functionally similar to the for loop example. The startup and update
processes are managed independently.
3. do-while Loop:
The do-while loop resembles the while loop; however, the condition is assessed
subsequent to the execution of the loop body. This ensures that the loop body executes at
least once, regardless of whether the condition is originally false.
Syntax
do { // Loop body (code to be run iteratively) } while (condition);
Illustration:
Example
int i = 10; do { printf("Value of i: %d\n", i); i--; } while (i > 0);
In this example although i is originally 10, the loop body is run once prior to evaluating
the condition i > 0.