CT1 Set 4
CT1 Set 4
O O L rks ODE
T4
Sl.N
o
a) 30
b) 32
c) 36
d) 42
2 The format identifier ‘%Lf’ is also used for _____ data 1 2 1 1
type.
a) Unsigned Int
b) Double
c) Unsigned Long
d) Long Double
3 Consider the below Algorithm and find the Step Number 1 2 1 1
in which there is an error? Step1:
Start
Step 6: Stop.
a) Step 2
b) Step 3
c) Step 5
d) Step 4
Find the output for the following program 1 2 1 1
4 #include <stdio.h>
void main() {
inti=-1;
a) 1
b) -1
c) 0
d) 2
a) for
b) while
c) do while
d) switch
Which of the following is an invalid if-else statement? 2 2 3 1
7 a) if (if (a == 1)){}
b) if (a){}
c) if ((char) a){}
d) if (func1 (a)){}
8 Do-while loop terminates when conditional expression 2 2 3 1
returns?
a) One
b) Zero
c) Non - zero
d) None of the above
#include <stdio.h>
void main()
int k = 0;
for (k)
printf("Hello");
b) hello
c) Nothing
d) Varies
a) void *
b) Pointer of allocated memory type
c) void **
d) int *
II List out the rules to be followed in forming in identifier?
Combination of alphabets, digits (or) underscore
First character should be a Alphabet
No special characters other than underscore can be used
No comma / spaces allowed within variable name
A variable name cannot be a keyword
Variable names are case sensitive
13 Write the syntax for all the three iterative control statements
Iterative Statement in C
(OR)
statement to be executed;
or
{ statements to be executed }
The statement will be executed repeatedly as long as the test expression is true. The
statement can be simple or compound, though it is usually a compound statement.
It must include some features that eventually alters the value of the expression, thus
providing stopping condition for the loop.
16a. Illustrate two-dimensional arrays with example.
An array is a collection of fixed number values of a single type. Hence, an integer array
can only hold elements whose data type is also an integer.
A two-dimensional array in C can be thought of as a matrix with rows and columns. The
general syntax used to declare a two-dimensional array is:
svg viewer
int my_array[5][3];
The code above declares a one-dimensional array that has five elements. Each of these
five elements is themselves, an array of three integers. The following diagram shows a
simple way to visualize this:
An array of arrays is known as 2D array. The two dimensional (2D) array in C programming is
also known as matrix. A matrix can be represented as a table of rows and columns.
The syntax to declare the 2D array is
data_type array_name[rows][columns];
Initialization of 2D Array in C
In the 1D array, we don't need to specify the size of the array if the declaration and initialization
are being done simultaneously.
However, this will not work with 2D arrays. We will have to define at least the second
dimension of the array. The two-dimensional array can be declared and defined in the following
way.
int arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};
(OR)
16b. Write a C program to count the number of digits in given number
#include <stdio.h>
int main() {
long long n;
int count = 0;
printf("Enter an integer: ");
scanf("%lld", &n);
// iterate at least once, then until n becomes 0
// remove last digit from n in each iteration
// increase count by 1 in each iteration
do {
n /= 10;
++count;
} while (n != 0);
printf("Number of digits: %d", count);
}