0% found this document useful (0 votes)
16 views7 pages

C Unit-2 QB

The document outlines the objectives and outcomes of a course focused on implementing basic constructs and operators in C programming. It includes questions and answers related to standard I/O library functions, various types of operators, control statements, and looping constructs, along with example programs. Additionally, it provides exercises for students to practice their understanding of these concepts.

Uploaded by

Sinduja Baskaran
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)
16 views7 pages

C Unit-2 QB

The document outlines the objectives and outcomes of a course focused on implementing basic constructs and operators in C programming. It includes questions and answers related to standard I/O library functions, various types of operators, control statements, and looping constructs, along with example programs. Additionally, it provides exercises for students to practice their understanding of these concepts.

Uploaded by

Sinduja Baskaran
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/ 7

Page|1

Unit II
OPERATOR AND EXPRESSIONS
Course Objective – COb 2: To implement programs using basic constructs of C

Course Outcome – CO2: Develop simple applications using various operators


in C.

Bloom’s Taxonomy Level: K1, K2, K3


Part A

S.No BTL
Question
. *
1. What is Standard I/O library functions and list 3 processing functions? K1
In C Language input and output function are available as C compiler
functions or C libraries provided with each C compiler implementation.
These all functions are collectively known as Standard I/O Library
function.
Here I/O stands for Input and Output used for different inputting and
outputting statements. These I/O functions are categorized into three
processing functions.
i. Console input/output function
ii. Disk input/output function
iii. Port input/output function
2. What is Console input/output function? K1
All the input/output statements deals with the console, so these are
also Console Input/Output functions. Console Input/Output function
access the three major files before the execution of a C program. They are,
i. Standard input (stdin)
ii. Standard Output (stdout)
iii. Standard Error (stderr)
3. Write about getchar() and putchar() functions. K1
getchar(): It is used for reading a single character from the keyboard. It is a
buffered function. Buffered functions get the input from the keyboard and
store it in the memory buffer temporally until you press the Enter key.
putchar():This function is an output function. It is used to display a single
character on the screen.
Eg. char initial; initial = getchar(); putchar(initial);
4. Define getch(). K1
It is a function is present in conio.h header file. It is used to read a single
character from the keyboard similar to getchar() function. The entered
character is immediately returned without waiting for the enter key. The
entered character does not show up on the console. So it can be used to accept
hidden passwords.
Eg. char pwd; pwd = getchar();
Page|2

5. Write a C program to explain the use of getch() function. K3


#include <stdio.h>
int main()
{
char n;
puts("Enter the Char");
n = getch();
puts("Char is :");
putchar(n);
getch();
}
Output:
Enter the Char L
Char is L
6. Define printf and scanf. K1
printf()
This is an output function. It is used to display a text message and to
display the mixed type (int, float, char) of data on screen. The general syntax
is as below:
printf("control strings", v1, v2, v3, ............. , vn);
Eg. printf(“ID: %d \n NAME: %s”, id, name);
scanf()
The scanf() function is an input function. It used to read the mixed
type of data from keyboard. You can read integer, float and character data by
using its control codes or format codes. The general syntax is as below:
scanf("control strings", &arg1, &arg2, ............. , &argn);
Eg. scanf(%s %d”, name, &age);
7. What are Operators? What are the different types of operators? K1
Operators are one of the features in C which has symbols that can be used to
perform mathematical, relational, bitwise, conditional, or logical
manipulations. An operator is a symbol that are used to perform operations
on variables and values.
The different types of operators in C are:
 Arithmetic Operators
 Relational Operators
 Logical Operators
 Bitwise Operators
 Assignment Operators
 Miscellaneous Operators
8. What are Arithmetic Operators? K1
Arithmetic Operators are the type of operators in C that are used to perform
mathematical operations on operands in a C program. They can be used in
programs to define expressions and mathematical formulas. The different
arithmetic operators in C are +, -, *, /, %
Page|3

9. Define Logical Operator. K1


Logical Operators are used to combine two or more conditions/constraints or
to complement the evaluation of the original condition in consideration. The
result of the operation of a logical operator is a boolean value either true or
false. The different logical operators in C are &&, ||, !
10. Write a note on increment and decrement operators. K1
The increment operator ( ++ ) is used to increment the value of a variable
in an expression by 1. It can be used on variables of the numeric type such as
integer, float, character, pointers, etc. Eg. int a; a++; ++a;
In pre-increment, the value is incremented first according to the
precedence and then the less priority operations are done. In post-increment,
the increment operator is used as the suffix of the operand.
The decrement operator ( -- ) is used to decrement the value of a variable
by 1 in an expression. Eg. int a; a--; --a;
In the Pre-Decrement, the value is first decremented and then used inside the
expression. Whereas in the Post-Decrement, the value is first used inside the
expression and then decremented.
11. What is ternary operator? K1
We use the ternary operator in C to run one code when the condition is true
and another code when the condition is false.
Syntax: testCondition ? expression1 : expression 2;
Eg. (age >= 18) ? printf("Can Vote") : printf("Cannot Vote");
12. What is an expression in C? What are the ways of writing an expression K1
in C?
An expression in C is a
combination of operands and
operators – it computes a single
value stored in a variable. The C
Expressions can be defined by
the number of operands,
operators, and their positions.
13. Define if statement. Also draw its flow diagram. K1
‘If’ is the most powerful decision-
making statement in C language. Thus, it is used
to control the execution of statements. ‘If’ is
used along with an expression. It is a two-way
branching or decision-making statement.

Syntax:
if (test expression)
{
Statements;
}
Page|4

14. K3
Write a C program for printing the numbers from 1 to 10 using for loop.
#include <stdio.h>
int main()
{
int i;
for (i = 1; i < 11; ++i)
{
printf("%d ", i);
}
return 0;
}

15. What is switch K2


Syntax:
statement? switch(expression)
Write its syntax. {
case constant-expression :
statement(s);
break; /* optional */
case constant-expression :
statement(s);
break; /* optional */
/* you can have any number of case statements */
default : /* Optional */
statement(s);
}

A switch statement allows a variable to be tested for equality against a list of


values. Each value is called a case, and the variable being switched on is
checked for each switch case.
Page|5

16. Differentiate break and continue statements. K2


break: A branching statement that terminates the existing structure.
continue: A branching statement that causes a loop to stop its current
iteration and begin the next one.

17. K2
Describe the syntax of for loop.
Syntax:
for (initialize expression; test expression; update expression)
{
body of for loop;
}

 Initialization Expression: In this expression, we assign a loop variable or


loop counter to some value. for example: int i=1;
 Test Expression: In this expression, test conditions are performed. If the
condition evaluates to true then the loop body will be executed and then
an update of the loop variable is done. If the test expression becomes false
then the control will exit from the loop. for example, i<=9;
 Update Expression: After execution of the loop body loop variable is
updated by some value it could be incremented, decremented, multiplied,
or divided by any value.
Write a C program to fin the sum of numbers from 1 to 5 using while K3
18. loop.
#include <stdio.h>
int main()
{
int i = 1, sum = 0;
Page|6

while (i <= 5) {
sum = sum + i;
++i;
}
printf("Sum of 1 to 5 = %d", sum);
return 0;
}
19. Differentiate between formatted and unformatted you input and output
functions?
Formatted I/P functions:
These functions allow us to supply the input in a fixed format and let us obtain
the output in the specified form. Formatted output converts the internal binary
representation of the data to ASCII characters which are written to the output K2
file.
Ex: printf, scanf functions
Unformatted I/O functions:
There are several standard library functions available under this category- those
that can deal with a string of characters. Unformatted Input/Output is the most
basic form of input/output. Unformatted input/output transfers the internal
binary representation of the data directly between memory and the file.
Ex: gets,puts, getchar,putchar functions

20. What is the basic difference between for loop and while loop? K2
For loop is used when the number of iterations is known already.
Initialization of iteration variable, test condition and update of the iteration
variable are built-in in the for loop statement.
While loop is used when the number of iterations is not known already. The
iteration variable is initialized before the loop starts, and it is updated in every
iteration of the loop.
21. What are the differences between while loop and do-while loop? K2
WHILE LOOP DO-WHILE LOOP
Entry controlled loop Exit controlled loop
In while-loop, the given condition In do-while-loop, the given body of
is evaluated first and then the body the loop is executed first and then
of the loop is executed. the given condition is checked.
The body of the loop would be The body of the loop would be
executed only if the condition is executed at least once even if the
true. condition is false.
Syntax: Syntax:
while(condition) do
{ {
Body of the loop; Body of the loop;
} } while(condition);
Page|7

Part B
S.No. Question BTL *
1. Explain the various input and output statements in C. K1
What are the different types of operators in C? Discuss each one of them
2. K2
with suitable illustrations.
a) Explain in detail about expressions in C. (8
marks) K2
3. b) What is precedence and order of evaluation? Explain in detail. (8 K2
marks)
4. Explain about decision making statements with suitable examples. K1
Explain switch statement with relevant example. (8
marks) K1
5. Write a C program to design a simple calculator. (8 K3
marks)
Write in detail about the various looping statements available in C with
6. illustrative programs. K2
a) Write a C program to reverse the digits of a number. (8
marks) K3
7. b) Write a C program to display the Fibonacci series. (8 K3
marks)
a) Write a C program to solve a quadratic equation. (8 marks)

b) Write a C program to check whether a given number is prime or not. K3


8.
K3
(8 marks)
9. a) Write a C program for finding whether given number is Armstrong
number or not. (8 marks)
b) Write a C program to find whether the given number is palindrome or K3
not. (8 marks) K3

10. a) Write a C program to find the factorial of a given number. (8 marks) K3


K3
b) Write a C program to find the sum of a digits of a number.
(8 marks)

You might also like