Unit Iqa
Unit Iqa
1. List and explain the functions of various parts of computer hardware and software.
Ans : Computer System :
A computer is a system made up of two major components:
I. Computer Hardware.
II.Computer Software.
1
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
C. Primary Storage: It is also known as main memory . It is a place where the programs
and data is stored temporarily during processing. The Data in primary storage is erased
, when we turn off a personal computer or when we log off from a time-sharing
computer ( volatile ).
E. Auxiliary Storage Devices ( secondary storage devices ): It is used for both input and output.
It is also known as secondary storage. It is a place where the programs and data are
stored permanently. when we turn off the computer the programs and data remain in the
secondary storage, ready for the next time when we need them.
II. Computer Software : Software is the collection of Programs ( instructions ) that allow
the hardware to do its job.
They are two types of Computer Software.
A. System Software
B. Application Software
2
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
i. Operating System Software: It provides services such as a user interface, files and data
base access and interfaces to communication systems such as Internet protocols. The
primary purpose of this software is to keep the system operating in an efficient manner
while allowing the users access to the system.
ii. System Support Software : System Support Software provides system utilities and other
operating services. Examples of system utilities are sort programs and disk format programs.
Operating services consist of programs that provide performance statistics for the operational
staff and security monitors to protect the system and data.
iii. System Development Software: It includes language translators that convert programs in to
machine language for execution , debugging tools to ensure that programs are error - free and
computer -assisted software engineering ( CASE ) systems.
B. Application Software: It is directly responsible for helping users to solve their problems.
Application software is broken in to two classes.
i. General - Purpose Software
ii. Application - Specific Software
i. General Purpose Software: It is purchased from a software developer and can be used for
more than one application. Examples: word processors, database management systems, computer –
aided design systems. They are labeled general purpose because they can solve a variety of
user computing problems.
ii. Application Specific Software: It can be used only for its intended purpose.
Example: A general ledger system used by accountants.
3
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
They can be used only for the task for which they were designed.They can not be used
for other generalized tasks.
Relationship between system and application software is shown in the figure:
A. Writing and Editing Program : The Software to write programs is known as text
editor. A text editor helps us enter , change and store character data. Depending on the
editor on our system, it could be used to write letters, create reports or write programs.
Example : word processor.
The text editor could be generalized word processor, but every compiler comes with
associated text editor. Some of the features of editors are
Search : To locate and replace statements.
4
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Copy , Paste : To copy and move statements.
Format : To set tabs to align text.
After the program is completed the program is saved in a file to disk. This file will be
input to the compiler, it is known as source file. The following figure shows the
various steps in building a C – program.
B. Compiling Programs: The code in a source file on the disk must be translated in
to machine language. This is the job of compiler which translates code in source file
stored on disk in to machine language. The C compiler is actually two separate
programs: the preprocessor and the translator. The preprocessor reads the source code
and prepares it for the compiler. It scans special instructions known as preprocessor
commands. These commands tell the preprocessor to take for special code libraries, make
substitutions in the code. The result of preprocessing is called translation unit. The
translator reads the translation unit and writes resulting object module to a file that
can be combined with other precompiled units to form the final program. An
object module is the code in machine language. This module is not ready for execution
because it does not have the required C and other functions included.
A. Understand the problem :The first step in solving any problem is understand it. We
begin by reading the requirements statements carefully.When we think that we fully understand
it, we review our understanding with the user and the system analyst.
Example: Calculate the square footage of house.
The questions that arise are
1. What is definition of square footage ?
2. How is it useful ?
C. Analysis: User requirements are transformed to technical terms like Blueprint and
also look for different alternatives considering all risks.
D. Design: In UML software users will develop flowcharts, structure charts, data flow diagrams
1. Choose the best way to find solution among different alternatives.
2. Choose in analysis , design files , databases and functions.
6
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
E. Code:
Unimportant in Software development life cycle
1. Uses software for code generation ( forward energy ).
2. Otherwise go for manual coding.
3. Basic testing is done ( compilation ).
F. System Test :Test if user requirements are met Blackbox Testing: Test programs
together, make sure system works as a whole. Whitebox Testing: Release ά-version to
customer, according to his/her feed back we develop β-Version: β - version is released to
selected group of people.
G.Maintenance :
Keeps the system working once it has been put in to production ?
Ans: Algorithm :
Algorithm is a finite set of instructions that , if followed accomplishes a particular task.
Algorithm should satisfy the following criteria
1. Input : Zero or more quantities are externally supplied.
2. Output : At least one quantity is produced.
3. Definiteness : Each instruction is clear and unambiguous. Ex Add B or C to A
4. Finiteness : Algorithm should terminate after finite number of steps
when traced in all cases
Ex: Go on adding elements to an array
5. Effectivenes: Every instruction must be basic i.e., it can be carried out,
by a person using pencil and paper.
Algorithm must also be general to deal with any situation.
Ans: Algorithm:
The same problem can be solved with different methods. So, to solve a problem different
algorithms, may be accomplished. Algorithm may vary in time, space utilized. User writes
algorithm in his / her own language. So, it can not be executed on computer. Algorithm
should be in sufficient detail that it can be easily translated in to any of the languages.
Example1 : Add two numbers.
Step 1: Start
Step 2: Read 2 numbers as A and B
Step 3: Add numbers A and B and store result in C
Step 4 : Display C
Step 5: Stop
Example2: Average of 3 numbers.
1. Start
2. Read the numbers a , b , c
3. Compute the sum and divide by 3
4. Store the result in variable d
5. Print value of d
6. End
Ans: Flowchart :
8
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
A flowchart is a visual representation of the sequence of steps for solving a
problem . A flowchart is a set of symbols that indicate various operations in the
program. For every process , there is a corresponding symbol in the flowchart . Once an
algorithm is written , its pictorial representation can be done using flowchart symbols. In other
words, a pictorial representation of a textual algorithm is done using a flowchart.
A flowchart gives a pictorial representation of an algorithm.
The first flowchart is made by John Von Neumann in 1945.
It is a symbolic diagram of operations sequence, dataflow, control flow and processing logic in
information processing.
The symbols used are simple and easy to learn.
It is a very helpful tool for programmers and beginners.
Purpose of a Flowchart :
Provides Communication.
Provides an Overview.
Shows all elements and their relationships.
Quick method of showing Program flow.
Checks Program logic.
Facilitates Coding.
Provides Program revision.
Provides Program documentation.
Advantages of a Flowchart :
Flowchart is an important aid in the development of an algorithm itself.
E asier to Understand than a Program itself.
Independent of any particular programming language.
Proper documentation.
Proper debugging.
Easy and Clear presentation.
Limitations of a Flowchart :
Complex logic.
Drawing is time consuming.
Difficult to draw and remember.
Technical detail.
9
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Step 1 : Start
Step 2 : Input num1 , num2
Step 3 : temp = num1
Step 4 : num1 = num2
Step 5 : num2 = temp
Step 6 : Output num1 , num2
Step 7 : Stop
Step 1 : Start
Step 2 : Input num1 , num2
Step 3 : calculate num1 = num1 + num2
Step 4 : calculate num2 = num1 – num2
Step 5 : calculate num1 = num1 – num2
10
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Step 6 : Output num1 , num2
Step 7 : Stop
Flowcharts :
10. Write an algorithm and flowchart to find the largest among two numbers.
Ans:
Algorithm:
Step 1 : Start
Step 2 : Input A , B
Step 3 : if A > B then output A
else output B
Step 4 : Stop
Flowchart :
11
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
11. Write an algorithm and flowchart to find the largest among three numbers.
Algorithm: (method 1)
Step 1 : Start
Step 2 : Input A, B, C
Step 3 : if A > B go to step 4 , otherwise go to step 5
Step 4 : if A > C go to step 6 , otherwise go to step 8
Step 5 : if B > C go to step 7, otherwise go to step 8
Step 6 : print “ A is largest ” , go to step 9
Step 7 : print “ B is largest ”, go to step 9
Step 8 : print “ C is largest ” , go to step 9
Step 9 : Stop
Flowchart:
12
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Algorithm: b.
Step 1 : Start
Step 2 : Input A, B, C
Step 3 : Let max = A
Step 4 : if B > max then max = B
Step 5 : if C > max then max = C
Step 6 : output max is largest
Step 7 : Stop
Flowchart:
13
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
14
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Flow chart:
13. Write an algorithm and flowchart to find whether a number is prime or not.
Hint: A number is said to be prime number for which the only factors are 1 and itsel
Algorithm:
Step 1: Start
Step 2: Input n
Step 3: Let i = 1, count=0
Step 4: if i > n/2 go to step 7
Step 5: if (n % i = = 0) count = count + 1
Step 6: increment i and go to step 4
Step 7: if count=2 then print “prime number” else print “not prime number”
Step 8: Stop
15
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Flow chart:
16
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Step 6: rev = (rev * 10) + digit
Step 7: n = n / 10 then go to step 4
Step 8: output rev
Step 9: Stop
15. Write an algorithm and flowchart to find the Sum of individual digits if a given number
Algorithm :-
Step 1 : Start
Step 2 : read n
Step 3 : Sum = 0
Step 4 : While n > 0 do
4.1 : r = n % 10
4.2 : Sum = Sum + r
4.3 : n = n/10
Step 5 : End while
Step 6 : Write Sum
Step 7 : Stop
17
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Flowchart :-
16. what is the general structure of `C' program and explain with example?
18
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
This section consists of a set of comment lines giving the name of the program, and other details.
In which the programmer would like to user later.
Ex:- /*………………………*/
Link section: Link section provides instructions to the compiler to link functions from the
system library.
Ex:- # include<stdio.h>
# include<conio.h>
Global declaration section: Some of the variables that are used in more than one function
throughout the program are called global variables and declared outside of all the functions. This
section declares all the user-defined functions.
Every C program must have one main ( ) function section. This contains two parts.
i) Declaration part: This part declares all the variables used in the executable part.
19
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Ex:- int a,b;
ii) Executable part: This part contains at least one statement .These two parts must appear
between the opening and closing braces. The program execution begins at the opening brace and
ends at the closing brace. All the statements in the declaration and executable parts end with a
semicolon (;).
This section contains all the user-defined functions, that are called in the main () function. User-
defined functions generally places immediately after the main() function, although they may
appear in any order.
Ex:
17. What is a variable? and write the rules for constructing variable?
Variables: It is a data name that may be used to store a data value. It cont be changed during the
execution of a program. A variable may taken different values at different times during
execution.
Rules: Variable names may consist of letters, digits and under score( _ ) character.
The declaration of variables must be done before they are used in the program.
Data-type v1,v2,…….,vn;
V1,v2,…vn are the names of variables. Variables are separated by commas. A declaration
statement must end with a semicolon. For example , valid declarations are:
int count;
double ratio;
Ex:
main()/*…………….Program Name……………..*/
/*……………….Declaration…………………………..*/
float x,y;
int code;
21
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
short int count;
double deviation;
unsigned n;
char c;
/*…………………………Computation…………………………*/
/*…………………………Program ends…………………..*/
Initialization of variable :
Initialize a variable in c to assign it a starting value. Without this we can't get whatever
happened to memory at that moment.
C does not initialize variables automatically. So if you do not initialize them properly, you
can get unexpected results. Fortunately, C makes it easy to initialize variables when you
declare them.
For Example :
int x=45;
DATA TYPES
Data type is the type of the data that are going to access within the program. C supports different
data types. Each data type may have pre-defined memory requirement and storage
representation. C supports 4 classes of data types.
i) Integer (int)
ii) Character(char)
iii) Floating (float)
iv) Double – precision floating point(double)
1. Integer types:
Integers are whole numbers with a range of values supported by a particular machine. Integers
occupy one word of storage and since the word size of the machine vary. If we use 16 bit word
length the size of an integer value is -32768 to +32767. In order to control over the range of
numbers and storage space, C has 3 classes of integer storage, namely short, long, and unsigned.
%d (or) %i
Unsigned short int 0 to 255 1 byte
2. Character type:-
Single character can be defined as a character (char) type data. Characters are usually stored in 8
bits of internal storage. Two classes of char types are there.
23
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Signed char(or) char 1 byte- -128 to +127%c
Floating point (real) numbers are stored in 32 bits, with 6 digits of precision when accuracy
provided by a float number is not sufficient
Double data type number uses 64 bits giving a precision of 14 digits. These are known as double
precision no.s. Double type represents the same data type that float represents, but with a greater
precision. To extend the precision further, we may we long double which uses 80 bits.
C –supports a feature known as “type definition” that allows users define an identifier that would
represents an existing type.
Identifier indicates the new name that is given to the data type.
typedef cont create a new data type ,it can rename the existing datatype. The main advantage
of typedef is that we can create meaningful datatype names for increasing the readability of the
program.
24
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Where identifier is user-defined datatype which is used to declare variables that can have one of
the values enclosed within the braces. Value1 ,value2,.valuen all these are known as enumeration
constants.
V1=value3;
V2=value1;………
Ex:- enum day {Monday,Tuesday…………. sunday};
Enum day week-f,week-end
Week-f = Monday
-
-
-
-
(or)
enum day{Monday…Sunday}week-f, week-end;
20. (a) Describe the different types of constants in C with example?
(b) What are the rules for creating C constants explain with example?
TYPES OF C CONSTANTS
1. Integer constants
2. Real constants
3. Character constants
4. String constants
1. Integer constants: An integer constant refers to a sequence of digits. There are three types of
integers, namely, decimal integer, octal integer and hexadecimal integer.
2. Real constants: These quantities are represented by numbers containing fractional parts like
18.234. Such numbers are called real (or floating point) constants.
25
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Examples of Real Constants:
+325.34
426.0
-32.67 etc.
The exponential form of representation of real constants is usually used if the value of the
constant is either too small or too large. In exponential form of representation the Real Constant
is represented in two parts. The first part present before 'e' is called Mantissa and the part
following 'e' is called Exponent.
For ex. .000342 can be written in Exponential form as 3.42e-4.
3. Single Character constants: Single character constant contains a single character enclosed
within a pair of single quote marks.
Note that the character constant’5’ is not same as the number 5. The last constant is a blank
space.Character constant has integer values known as ASCII values. For example, the statement
Printf(“%d”,a); would print the number 97,the ASCII value of the letter a. Similarly, the
statement printf(“%c”,97); would output the letter ‘a’
String constants: A string constant is a sequence of character enclosed in double quotes. the
characters may be letters, numbers, special characters and blank space.
Examples are:
“HELLO!”
“1979”
“welcome”
“?.......!”
“5+3”
26
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
“X”
21. What is an operator and List different categories of C operators based on their
functionality? Give examples?
Operators:
27
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
An operator is a symbol performs certain mathematical or logical manipulations. Operators are
used in programs to manipulate data variables.
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
6. Conditional operators
7. Bitwise Operators
8. Special operators
1. Arithmetic Operators:
The arithmetic operators are
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo division
Here a and b are operands, assign values for a=14 and b=4 we have the following results
a-b = 10
a+b = 18
a*b = 56
28
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
a/b = 3(coefficient)
a%b = 2(remainder)
2.Relational Operators:
Relational operators are used for comparing two quantities, and take certain decision. For
example we may compare the age of two persons or the price of two items….these comparisons
can be done with the help of relational operators.
Operator Meaning
< is less than
<= is less than or equal to
> is greater than t
>= is greater than or equal to
== is equal to
!= is not equal to
Ex:- 4.5<=10(true)
6.5<-10(false)
10<4+12(true)
When arithmetic expression are used on either side of a relational operator, the arithmetic
expression will be evaluated first and then the results compared, that means arithmetic operators
have a higher priority over relational operators.
3. Logical Operator:
C has 3 logical operators. The logical operators are used when we want to test more than one
condition and make decisions.
Operator Meaning
&& Logical AND
|| Logical OR
29
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
! Logical NOT
The logical operators && and || are used when we test more than one condition and make
decisions.
This expression combines two or more relational expressions, is termed as a logical expression
or a compound relational expression. The logical expression given above is true only if a>b is
true and x==10 is true. if both of them are false the expression is false.
4. Assignment operator:
These operators are used to assign the result of an expression to a variable. The usual
assignment operator is ‘=’
V op = exp;
Ex:- X= X+(Y+1);
a*=a;----- a=a*a;
++ and - - are increment and decrement operators in C. The operator ++ adds 1 to the
operand, while - - subtracts 1.both are unary operators.
30
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
++m; or m++; is equal to m=m+1(m+=1;)
We use the increment and decrement statements in for and while loops extensively.
Ex:- m=5;
A prefix operator first adds 1 to the operand and then the result is assigned to the variable on left.
On the other hand, a postfix operator first assigns the value to the variable on left and then
increments the operand.
6. Conditional operator:
The operator?: works as follows: exp1 is evaluated first. If it is non-zero (true), then the
expression exp 2 is evaluated and becomes the value of the expression. If exp1 is false, exp3 is
evaluated and its value becomes the value of the expression.
X = (a>b) ? a:b;
7. Bitwise Operator:
31
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
C supports a special operator knows as bitwise operators for manipulation of data at bit level.
These operators are used for testing the bits, or shifting them right to left. Bitwise operators may
not be applied to float or double.
Operator Meaning
& Bitwise AND
| Bitwise OR
ꞈ Bitwise exclusive OR
8. Special operators:
C supports some special operators such as comma operator, size of operator, pointer operator (&
and *) and member selection operators (. and -> ).
The comma operator: The comma operator is used to link the related expression together. A
comma linked list of expressions is evaluated left to right and the value of right- most expression
is the value of the combined expression. For example, the statement
The sizeof operator: The sizeof is a compile time operator and when used with an operand, it
returns the number of bytes the operand occupies. The operand may be variable, a constant or a
data type qualifier.
m = sizeof (sum);
32
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
The sizeof operator is normally used to determine the lengths of arrays and structures when their
sizes are not known to the programmer. It is also used to allocate memory space dynamically to
variables during execution of a program.
Type conversions: converting a variable value or a constant value temporarily from one data
type to other data type for the purpose of calculation is known as type conversion.
1. Implicit: In this higher data type can be converted into lower data type.
* Float value can be converted into integral value by removing the fractional part.
* Double value can be converted into float value by rounding of the digits.
* Long int can be converted into int value by removing higher order bits.
2. Explicit: In this type of conversion, the programmer can convert one data type to other data
type explicitly.
y= cos(double(x))
double a = 6.5
double b = 6.5
int a=10
33
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
float(a)->10.00000
Expressions:
a+b
tan(angle)
For example:
sum = x + y + z;
printf("Go Buckeyes!");
1)If an expression has parenthesis, sub expression within the parenthesis is evaluated
first and arithmetic expression without parenthesis is evaluated first.
3)the operators at same precedence are evaluated from left to right or right to
variable = expression;
Variable is any valid C variable name. when the statement is encountered, the expression is
evaluated first and the result then replaces the previous value of the variable on the left-hand
side. All variables used in the expression must be assigned values before evaluation is attempted.
Ex:- x = a*b-c;
34
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Y = b/c*a;
Z = a-b / c+d;
Ex:- x= a-b/3+c*2-1 when a=9, b=12, and c=3 the expression becomes.
x = 9-12/3 +3*2-1
Step1: x = 9-4+3*2-1
Step2: x = 9-4+6-1
Step3: x = 5+6-1
Step4: x = 11-1
Step5: x = 10
or
Operator Precedence:
Important note:
35
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Precedence rules decide the order in which different operators are applied
Associativity rule decides the order in which multiple occurrences of the same level
operator are applied.
Hierarchy Of Operations In C
There are some operators which are given bellow with their mean. The higher the position of
an operator is, higher is its priority.
Operator Type
! Logical NOT
+- Arithmetic
==!= Relational
|| Logical OR
= Assignment
ASSOCIATIVITY OF OPERATOR
When an expression contains two operators of equal priority the tie between them is
settled using the associatively of the operators.
While executing an arithmetic statement, which has two or more operators, we may have
some problem as to how exactly does it get executed.
multiplication,
division,
1st *, / , %
modular
division
addition,
2nd +, -
subtraction
3rd = assignment
For Example :
i= 2*3/4+4/4+8-2+5/8
i=6/4+4+8-2+5/8
i=1+4/4+8-2+5/8
i=1+1+8-2+5/8
i=1+1+8-2+0
i=2+8-2+0
i=10-2+0
i=8+0
i=8
25. (a) Explain the formatted I/O functions with example? (8)
Reading, processing and writing of data are the three essential functions of a computer program.
Most programs take some data as input and display the processed data. We have two methods of
providing data to the program variables. One method is to assign values to variables through the
assignment statements like x=5, a=0 and so on. Another method is to use the input function
scanf, which can read data from a keyboard. We have used both the methods in programs. For
37
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
outputting results, we have used extensively the function printf, which sends results out to a
terminal.
The program takes some I/P- data, process it and gives the O/P.
We have two methods for providing data to the program
C language has 2 types of I/O statements; all these operations are carried out through function
calls.
getchar( ):- It reads single character from standard input device. This function don’t require any
arguments.
Ex:- char x;
x = getchar( );
putchar ( ):- This function is used to display one character at a time on the standard output
device.
Syntax:- putchar(char_variable);
Ex:- char x;
Putchar(x);
Ex:- main( )
Char ch;
Printf(“enter a char”);
38
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Ch = getchar( );
Putchar(ch);
getc() :- This function is used to accept single character from the file.
Ex:- char c;
c = getc();
Ex:- charc;
Putc(c);
gets( ):- This function is used to read group of characters(string) from the standard I/P device.
Ex:- gets(s);
Puts( ):- This function is used to display string to the standard O/P device.
Ex:- puts(s);
Ex:- main()
{
char s[10];
Puts(“enter name”);
39
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
gets(s);
puts(“print name”);
puts(s);
getch():- This function reads single character directly from the keyboard without displaying on
the screen. This function is used at the end of the program for displaying the output (without
pressing (Alt-F5).
Ex:- char c
c = getch();
getche():- This function reads single character from the keyboard and echoes(displays) it to the
current text window.
Ex:- char c
c = getche();
ex:- main()
{
char ch, c;
Printf(“enter char”);
ch = getch();
printf(“%c”, ch);
printf(“enter char”);
c = getche();
printf(“%c”,c);
}
40
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
O/P:- enter character a
Enter character b
Function Test
isainum(c) Is c an alphanumeric character?
isalpha(c) Is c an alphabetic character
isdigit(c) Is c is a digit?
islower(c) Is c lower case letter?
isprint(c) Is c printable character?
ispunct(c) Is c a punctuation mark?
isspace(c) Is c a while space character?
isupper(c) Is c an upper case letter?
tolower(c) Convert ch to lower case
toupper(c) Convert ch to upper case
Ex:- main()
Char a;
Printf(“enter char”);
a = getchar();
if (isupper(a))
x= tolower(a);
putchar(x);
else
41
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
putchar(toupper(a));
Formatted I/O Functions: Formatted I/O refers to input and output that has been arranged in a
particular format.
scanf( ) :- scanf() function is used to read information from the standard I/P device.
Ex:- int n;
Scanf(“%d”,n);
Control string represents the type of data that the user is going to accept. & gives the address of
variable.(char-%c , int-%d , float - %f , double-%lf). Control string and the variables going to I/P
should match with each other.
4 3 7 7
Printf( ): This function is used to output any combination of data. The outputs are produced in
such a way that they are understandable and are in an easy to use form. It is necessary for the
programmer to give clarity of the output produced by his program.
42
Q&A for Previous Year Questions Subject: CPDS (B.Tech. I Year) Subject Code: GR11A1003
UNIT-I
------------------------------------------------------------------------------------------------------------------------------------------
Control string consists of 3 types of items
Format O/P
9 8 7 6
Printf(“%d”, 9876)
9 8 7 6
Printf(“%6d”,9876)
9 8
Printf(“%2d”,9876)
9 8 7 6
Printf(“%-6d”,9876)
Printf(“%06d”,9876) 0 0 9 8 7 6
w---- Indicates minimum number of positions that are to be used for display of the value.
Printf(“%7.4f”,y) 9 8 . 7 6 5 4
Printf(“%7.2f”,y) 9 8 . 7 7
9 8 . 7 7
Printf(“%-7.2f”,y)
9 . 8 8 e + 0 1
Printf(“%10.2e”,y)
Format O/P
%s R a j u R a j e s h R a n i
%18s R a j u R a J e s h R a n i
%18s R A j u R a j E s h R a n i
44