c programming (1)
c programming (1)
SECTION – A
Answer the following questions [10 X 2 =20 ]
1] what is computer ? [2019 ,2018]
-> A computer is a programmable electronic device that accepts raw data as
input and processes it with a set of instructions (a program) to produce the result as
output.
It renders output just after performing mathematical and logical operations
and can save the output for future use.
It can process numerical as well as non-numerical calculations. The term
"computer" is derived from the Latin word "computer" which means to calculate.
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
-> A data type specifies the type of data that a variable can store such as
integer, floating, character, etc.
Types Data Types
Enumeration enum
Data Type
Void Data Type void
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
-> Recursion is the process which comes into existence when a function calls
a copy of itself to work on a smaller problem. Any function which calls itself is called
recursive function, and such function calls are called recursive calls. Recursion
involves several numbers of recursive calls.
-> The simplest way to initialize an array is by using the index of each
element. We can initialize each element of the array by using the index.
Consider the following example.
marks[0]=80;//initialization of array
marks[1]=60;
marks[2]=70;
marks[3]=85;
marks[4]=75; Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
-> if (condition1)
{
// Executes when condition1 is true
if (condition2)
{
// Executes when condition2 is true
}
}
-> we can divide a large program into the basic building blocks known as
function. The function contains the set of programming statements enclosed by
{}. A function can be called multiple times to provide reusability and modularity
to the C program. In other words, we can say that the collection of functions
creates a program. Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
SECTION – B
Answer the following questions [4 X 5 =20 ]
Input Devices
CPU
Output Devices
Primary Memory
Secondary Memory
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
1) Inputting: It is the process of entering raw data, instructions and information into
the computer. It is performed with the help of input devices.
2) Storing: The computer has primary memory and secondary storage to store data
and instructions. It stores the data before sending it to CPU for processing and
also stores the processed data before displaying it as output.
3) Processing: It is the process of converting the raw data into useful information. This
process is performed by the CPU of the computer. It takes the raw data from
storage, processes it and then sends back the processed data to storage.
5) Controlling: This operation is performed by the control unit that is part of CPU.
The control unit ensures that all basic operations are executed in a right manner
and sequence. Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Compact Disc-Read Only Memory A type of CD disc that can only be read, but not
recorded.
Used to store programs and data files, a CD-ROM holds 650MB or 700MB of data
An audio CD player cannot read CD-ROMs, but CD-ROM drives can play audio discs.
In practice, the term "CD" refers to all CD formats. The phrase "insert the installation
CD" really means "insert the installation CD-ROM.“
CD-ROM is an optical disc containing audio or software data whose memory is read-
only A CD-ROM Drive or optical drive is the device used to read them.
CD-ROM drives have speeds ranging from 1x to 72x, meaning it reads the CD roughly
72 times faster than the 1x version.
As you would imagine, these drives are capable of playing audio CDs and reading data
CDs, including CD-Rand CD-RWdiscs.
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
#include <stdio.h>
int main()
{
int x, y, t;// x and y are the swapping variables and t is another variable
printf("Enter the value of X and Y\n");
scanf("%d%d", &x, &y);
printf("before swapping numbers: %d %d\n",x,y);
/*swapping*/ Output:
t = x;
x = y; Enter the value of X and Y
y = t; 29 39
printf("After swapping: %d %d",x,y); before swapping numbers: 29 39
return 0; After swapping: 39 29
}
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Speed :
A computer works with much higher speed and accuracy compared
to humans while performing mathematical calculations.
Accuracy
Computers perform calculations with 100% accuracy. Errors may
occur due to data inconsistency or inaccuracy.
Diligence
A computer can perform millions of tasks or calculations with the
same consistency and accuracy. It doesn’t feel any fatigue or lack of
concentration.
Versatility
Versatility refers to the capability of a computer to perform different kinds of
works with same accuracy and efficiency.
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Reliability
A computer is reliable as it gives consistent result for similar set of data i.e.,
if we give same set of input any number of times, we will get the same result.
Memory
A computer has built-in memory called primary memory where it stores
data. Secondary storage are removable devices such as CDs, pen drives, etc., which
are also used to store data.
-> Basically structure of the C program is divided into six different sections,
Documentation section:
The Documentation section consists of a set of comment lines.
Link section:
The link section provides instruction to the compiler to link the header files or
functions from the system library.
Definition section:
The definition section defines all symbolic constants such by using theBca Expert
#define
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Global declaration section:
There are some variables that are used in more than one function,
such variables are called global variables.
In C there are two types of variable declaration,
Local variable declaration: Variables that are declared inside the main function.
Global variable declaration: Variables that are declared outside the main
function.
Sub-program section:
If the program is a multi-function program, then the subprogram
section contains all user-defined functions that are called in the main() function.
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
8] describe the basic steps involve in problem solving [ 2017 ]
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
SECTION – C
Answer the following questions [4 X 10 =40 ]
1] mention the features of C language and explain the basic structure
of a C program [ 2019, 2018 ]
->C is the widely used language. It provides many features that are given below.
Simple
Machine Independent or Portable
Mid-level programming language
structured programming language
Rich Library
Memory Management
Fast Speed
Pointers
Recursion
Extensible
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Documentation Section
The documentation section is the part of the
program where the programmer gives the details
associated with the program.
Link Section
This part of the code is used to declare all the
header files that will be used in the program. This leads
to the compiler being told to link the header files to the
system libraries.
Definition Section
In this section, we define different constants. The
keyword define is used in this part.
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
-> An operator is simply a symbol that is used to perform operations. There can
be many types of operations like arithmetic, logical, bitwise, etc.
Arithmetic Operators
Increment Operator in C
Decrement Operator in C
Assignment Operator
Relational Operators in C
Logical Operators in C
Conditional Operator in C
Bitwise Operator in C
. Misc operators in C
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
1. Arithmetic Operators in C
The purpose of this operator is to perform mathematical operations like
addition, subtraction, division, multiplication etc.
2. Increment Operator in C
Mainly used for incrementing the value of an integer. It is represented by
the ‘++’ operator. ++x will increase the value of the variable x instantly. But if it is
placed after the variable then it gets increased before the execution of the next
statement.
3. Decrement Operator in C
Mainly used for decrementing the value of an integer. It is represented by
the ‘–’ operator. –x will decrease the value of the variable x instantly. But if it is
placed after the variable then it gets decreased before the execution of the next
statement.
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
4. Assignment Operators in C
The purpose of this operator is to assign value to a variable. The most
used assignment operator is “=”.
5. Relational Operators in C
Mainly used for checking relationships between operands. With the help
of this operator, you can check whether one operand is equal to or greater than
the other operand or not.
6. Logical Operators in C
In the C programming language, Logical operators are mostly used for
decision making. A logical operator returns either 0 or 1 whether the condition is
true or false.
7. Conditional Operator in C
Also known as Ternary operator. The main purpose of conditional operators is in
decision making statements. It is similar to an if-else statement. Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
8. Bitwise Operator in C
C also provides special operators for bit operation between two variables.
9. Misc operators in C
It includes operators like sizeof(), reference operator(&), pointer
operator(*), condition operator(?).
Examples
break
The break is used in one of two ways; with a switch to make it act like a
case structure or as part of a looping process to break out of the loop. The
following gives the appearance that the loop will execute 8 times, but the break
statement causes it to stop during the fifth iteration
counter = 0;
While counter < 8
Output counter
If counter == 4
break counter += 1
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
continue
The following gives the appearance that the loop will print to the
monitor 8 times, but the continue statement causes it not to print number 4.
return
The return statement exits a function and returns to the statement
where the function was called.
Function DoSometing
Statements
Return <optional return value>
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Goto
The goto structure is typically not accepted in good structured programming.
However, some programming languages allow you to create a label with an identifier
name followed by a colon. You use the command word goto followed by the label.
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
6] explain with syntax switch case , while loop , and nested for loop
statements
[ 2021,2019, 2018, 2017,2016,2015,2014 ]
while loop in C
While loop is also known as a pre-tested loop. In general, a while loop
allows a part of the code to be executed multiple times depending upon a given
Boolean condition
while(condition)
{
//code to be executed
}
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Nested Loops in C
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
7] explain all
a) binary operators
b) relational operators
c) two dimensional array
d) call – by- references
e) go to statements
[ 2021,2019, 2018, 2017,2016,2015,2014 ]
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Arithmetic Operators
Increment Operator in C
Decrement Operator in C
Assignment Operator
Relational Operators in C
Logical Operators in C
Conditional Operator in C
Bitwise Operator in C
. Misc operators in C
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
b) relational operators
These operators are very helpful for making decisions. Depending upon the
condition, it returns either 0 or 1. When the condition with these operators is true, 1
is returned. If the condition is false, it returns 0.
Symbol Meaning
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
Flowchart is simple to
5. Algorithm is difficult to construct.
construct.
Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
-> The looping can be defined as repeating the same process multiple times
until a specific condition satisfies. There are three types of loops used in the C
language.
Advantage of loops in C
1) It provides code reusability.
2) Using loops, we do not need to write the same code again and again.
3) Using loops, we can traverse over the elements of data structures (array
or linked lists).
Types of C Loops
There are three types of loops in C language that is given below:
1) do while
2) while
Bca Expert
3) for
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
do-while loop in C
The do-while loop continues until a given condition satisfies. It is also called
post tested loop. It is used when it is necessary to execute the loop at least once
(mostly menu driven programs).
The syntax of do-while loop in c language is given below:
do{
//code to be executed
}while(condition);
while loop in C
The while loop in c is to be used in the scenario where we don't know the
number of iterations in advance. The block of statements is executed in the while
loop until the condition specified in the while loop is satisfied. It is also called a pre-
tested loop.
syntax : while(condition){
//code to be executed
} Bca Expert
C – PROGRAMMING
1st semester B.C.A
[ Rani Channamma university Belagavi ]
for loop in C
The for loop is used in the case where we need to execute some part of
the code until the given condition is satisfied. The for loop is also called as a per-
tested loop. It is better to use for loop if the number of iteration is known in
advance.
The syntax of for loop in c language is given below:
for(initialization;condition;incr/decr){
//code to be executed
}