Tutorial-1
1.Classify the following into valid and invalid C
integer constants:
a)
-67 b) 100
0 c)
10,000
d) +99 e)
0.5 f) 35
2. Pick the incorrect floating point constants and
give reasons:
a)40,945.65
b)428.58
c)46e2
d)465.
e)43
3. Convert the
following algebraic expressions into C equivalent expressions:
i) y=ax2 +
bx
+c
ii) area=√s(s-a)(s-b)(s-c)
iii)2x+3y
iv) y=α + β + |x| sinθ
3. Write the C statement using ternary operator to
perform the following:
a) Find the Largest of two numbers.
b) Check whether the given integer number is Positive or negative
c) Find the Largest of three numbers
d) Check whether a character is alphabet or not.
e) Check whether the alphabet is in lower case or upper case.
f) Convert the lower case alphabet to upper case and vice versa.
g) Check whether a given year is leap year or not.
h) Check whether the given integer number is odd or even.
Tutorial-2
1. Which of the
following are invalid Variable names and Why?
Minimum
First.name
n1+n2
&name
doubles
3rd_row
Row1
stud_avg
float
Sum
Total
n$
si-int
AVERAGE
Percent.
136
INT
2. Find errors, if any,
in the following declaration statements:
Int x;
float letter,
DIGIT;
double =p,q;
char ch c;
3. Point out the errors,
if any, in the following C statements:
int
=314.562*150;
name=’Ajay’;
3.14*r*r=area;
k=a*b+c(2.5a+b);
m_inst=rate*amount
in rs;
4. Evaluate the
following expressions and show their Hierarchy:
i) c=a/2 + a*4/a-a+b/3
(a=3, b=1.5, assume c to be a float)
ii) z=w*x/2 + 3/2*x + 2+y
(w=3, x=2, y=3.2, assume z to be an int)
iii) s=p*q/4-6/2+2/3*6/r
(p=2, q=4, r=3, assume s to be an int)
Tutorial-3
1. Find the sum of all the digits of an integer
number.
2. Find the sum of first and last digit of an integer
number.
3. Find the sum of odd numbers and sum of even numbers
in first n Natural numbers.
4. Generate and print the first n Fibonacci numbers.
5. Read n integer numbers and print the biggest and
smallest number without using arrays.
6. Print the output in the following format:
a) * * * *
* b) e
c) 1
d) 5 4 3 2 1
* * *
* e
d 2
1
4 3 2 1
* *
* e d
c 3 2
1 3 2 1
*
* e
d c b 4 3 2
1 2 1
* e
d c b a 5
4 3 2
1 1
7. Count the number of 1’s in the binary
representation of an integer number.
8. Read a binary number and convert it into decimal.
9. Read a decimal number and convert it into binary.
10. Read an integer
number and print the increment of each digit of that number.
Tutorial-4
1. State whether the
following statements are true or false:
a) All
arithmetic operators have the same level of precedence.
b) The modulus
operator % can be used only with integers.
c) An Unary
expression consists of only one operand with no operators.
d) During the
evaluation of mixed expressions, an implicit cast is generated automatically.
e) A switch
expression can be of any type.
f) One if can
have more than one else clause.
g) A program
stops its execution when a break statement is encountered.
2. Identify unnecessary
parentheses in the following arithmetic expressions:
a)
((x-(y/5)+z)%8)+25
b)
((x-y)*p)+q
c) (m*n) +
(-x/y)
d) x/(3*y)
3. Determine the value of each of the
following logical expressions if a=5,b=10 and
c=-6 :
c=-6 :
a) a >b
&&
a<c
b)
a<b && a>c
c) a==c ||
b>a
d) b>15 && c<0 || a>0
Tutorial-5
1. Write a for statement
to print each of the following sequences of integers :
a) 1, 2, 4, 8, 16,
32 b) 1, 3,
9, 27, 81, 243 c)
-4, -2, 0, 2, 4
2. State whether the
following statements are true or false:
a) The type of
all the elements in an array must be the same.
b) When an array
is declared, C automatically initializes its elements to zero.
c) Accessing an array outside its range is a compile time error.
c) Accessing an array outside its range is a compile time error.
d) In C, by
default, the first subscript of an array is zero.
e) The
declaration int x[2]={1,2,3}; is illegal.
3. Fill in the blanks in
the following statements:
a) The _______
operator is true only when both the operands are true.
b) Multi-way
selection can be accomplished using an else if statement or the_______
statement.
c) The _______ statement when executed in a switch statement causes immediate
exit from the structure.
statement.
c) The _______ statement when executed in a switch statement causes immediate
exit from the
d) The ________
operator returns the number of bytes the operand occupies.
e) The
sentinel-controlled loop is also known as _____________ loop.
f) In a
counter-controlled loop, variable known as __________ is used to count the loop
operations.
g)
One-dimensional array is also called as a __________________ .
h) __________
is the process of arranging the elements of an array in order.
4. Write C programs for
the following :
a) Read n integers
into an array. Find the largest and smallest number in the array.
b) Accept two
arrays A and B with 5 elements each. Find an array C such that
C[0]=A[0] +
B[0]
C[1]=A[1] +
B[1]
----
---- ----
C[4]=A[4] +
B[4]
c) Accept two
arrays A and B with 5 elements each. Find an array C such that
C[0]=A[0] +
B[4]
C[1]=A[1] +
B[3]
----
---- ----
C[4]=A[4] +
B[0]
d) Read m elements
into an array A and n elements into an array B. Append all the
elements of array B to A.
elements of
Tutorial-6
1. What will be the
output of the following C programs?
a) #define ABC
20
b)
#define calc(a,b)
(a*b)/(a-b)
#define XYZ
10
main(
)
#define XXX ABC –
XYZ
{
main(
)
int
a=20,b=10;
{
printf(“%d\n”,calc(a+4,b-2));
int
a;
}
a = XXX * 10;
printf("%d\n",
a);
}
c)
main(
)
d)
main(
)
e)
main( )
{
{
int
a=1,b=1;
{
char str[
]=”abcd”;
if(a==0)
printf(“%d”,3>>2?10:20);
printf(“%d”,sizeof(str));
if(b==0)
}
printf(“%d”,sizeof(“abcd”));
printf(“Hi”);
printf(“%d”,sizeof(‘a’));
else
f)
main( )
}
printf(“Bye”);
{
}
printf(“\nHe%cllo”,13);
}
g)
main(
)
h)
main( )
{
{
char
a[4]={‘x’,’y’,’z’,0};
printf(“\”Hi\\Bye%%%%End\””);
printf(“%s\n”,a);
}
}
2. Write C programs for the following.
a) Reverse the given array of n elements.
b) Read two arrays A and B each containing n elements.
Generate array C such
that
C[0]=A[0],
C[1]=B[0], C[2]=A[1], C[3]=B[1], ….C[n-2]=A[n-1], C[n-1]=B[n-1]
c) Insert an element into an array in a specified position
and print the array.
d) Generate and print first n Fibonacci numbers using array.
Tutorial-7
1. Write C programs for the following:
a) Find the
Norm of the given matrix of order m x n.
b) Find the
Transpose of the given matrix of order m x n.
c) Find the sum
of two matrices of order n x n.
d) Check
whether the two matrices are equal or not.
e) Generate the
multiplication table for first five numbers without using arrays.
1x1=1
2x1=2
3x1=3
4x1=4 5x1=5
1x2=2
2x2=4
3x2=6
4x2=8
5x2=10
. .
.
. . .
. .
. .
. .
. . .
1x10=10
2x10=20
3x10=30
4x10=40 5x10=50
f) Generate the
multiplication table for first five numbers using a 2D-array.
g) Check
whether the given matrix is a Symmetric matrix or not.
h) Find the Sum
of Non-principal diagonal elements of a matrix of order n x n.
i) Find the Sum
of secondary diagonal elements of a matrix of order n x n.
Tutorial-8
1. State
whether the following statements are true or false:
a) When
initializing a string variable during its declaration, we must include the NULL
character as
part of the string constant, like “GOOD\0”.
b) The gets( )
and scanf( ) functions automatically append the NULL character at the
end of the string read from the keyboard .
end of
c) String
variables cannot be used with assignment operator.
d) We cannot
perform arithmetic operations on character variables.
e) We can
assign a character constant or a character variable to an int type variable.
2. Assume that s1, s2, s3 and s4
are declared as follows:
char
s1[10]=”he”, s2[20]=”she”, s3[30], s4[30];
What will be
the output of the following statements executed in sequence?
printf(“ %s ”,
strcpy( s3, s1 ));
printf(“ %s ”,
strcat ( strcat ( strcpy ( s4, s1 ), ”or” ), s2 ) );
printf(“ %d
%d”, strlen(s2) + strlen(s3), strlen(s4));
3. Assuming the variable string contains the
value “The sky is the limit.”,
determine what will be the output of the following program segments.
determine what will be the output of the following program segments.
a) printf(“%s”, string);
b) printf(“%25.10s”,string);
c) for(i=0;string[i]!=’.’;i++)
printf(“%c”,string[i]);
d) printf(“%c\n”,string[10] + 5);
e) printf(“%c\n”,string[10]
+ ‘5’);
4. Write C programs for the following:
a) Find the first occurrence of a
character in a given string.
b) Check
whether two strings are equal or not.
c) Find the
last occurrence of a character in a given string.
d) Convert the
lowercase alphabets into uppercase in a given sentence.
e) Count the
number of words, lines, alphabets, digits, blank spaces and tab spaces
in a given paragraph of text.
in a given
f) Read a
word and sort each digit of the word in ascending order and display the
word.
word.
(Ex: If the word is “ HAI” then print the output
as “AHI”)
Tutorial-9
1.
Which of the following statements will correctly store the concatenation of
strings s1 and s2 in string s3?
strings s1 and s2 in
a) s3 =
strcat(s1,s2);
b)
strcat(s1,s2,s3);
c) strcat(s3,s2,s1);
d) strcpy(s3,strcat(s1,s2)); e)
strcmp(s3,strcat(s1,s2));
f) strcpy(strcat(s1,s2),s3);
2.
What will be the output of the following code?
char s1[ ]=”ANIL KUMAR GUPTA”;
char s2[ ]=”KUMAR”;
printf(“%s”,strstr(s1,s2));
Replace a
particular word by another word in a given string.
Delete a
specified word in a given sentence.
e) Read n names
in lower-case and store them in an array. Convert the first character of
each name into upper-case.
each
e) Convert the
uppercase alphabets into lowercase in a given sentence.
f) Read the
main string S1 and a substring S2. Find the first
occurrence of the substring
S2 in the main string S1.
S2 in the main
3. Write C programs
for the following:
a) Read n names
in lower-case and store them in an array. Convert the first character of
each name into upper-case.
b) Read the main
string S1 and a sub-string S2. Find
the first occurrence of the sub-string
S2 in the main string S1 without using built-in string functions.
c) Replace a
particular word by another word in a given string.
d) Delete a specified
word in a given sentence.
e) Print all the
rotations of a string. (For example, the rotations of word “space” are
space
paces acesp cespa espac )
f) Count the number of ‘e’ in the following
2D-character array:
char str[6][30]={ “ We will teach you how to . .
. ”,
“ Move a
mountain”,
“ Level a
building”,
“
Erase the past”,
“ Make a million”,
“ . . . all through C ! “
};
Tutorial-10
1. State whether the
following statements are true or false:
a) A function
in C should have at least one argument.
b) A function
can be defined within the main function.
c) A function
can call itself.
d) The return
type of a function is int by default.
2. Fill in the blanks in the
following statements:
a) The parameters used in a function
call are called _____________ .
b) A variable declared inside a
function is called _______________ .
c) In function prototype statement,
specifying ___________ is optional.
d) If a local variable has to retain
its value between calls to the function, it must be
declared as ___________ .
declared as
e) A variable declared inside a
function by default assumes _________ storage class.
f) A pointer variable contains as its
value the ________ of another variable.
g) The only integer that can be
assigned to a pointer variable is _____________ .
3. Determine the
output of the following program:
a) int
prod(int,int);
b) main(
)
c) #define MAIN main( )
main(
)
{
#define
Begin {
{
int abc(int);
#define End }
int
x=10,y=20,z=30;
int i = abc(100) = =
10; MAIN
int
p,q;
printf(“%d”\n”,i);
Begin
p =
prod(x,y);
}
printf(“Hello”);
q =
prod(p,prod(x,z));
int abc(int
i)
End
printf(“\n%d %d”,p,q);
{
}
return(i/10);
d)
#define i j
int prod(int a,int
b)
}
main(
)
{
{
return(a *
b);
int i = 10;
}
printf(“%d”,j);
}
4. Write C programs for the
following:
a) Find the sum of all the digits of an
integer number using:
i) non-recursive
function ii) recursive function
b) Read two integer arrays sorted in
ascending order and write a C function to merge the
two input arrays and store it in the third array.
two
c) Write a C function that takes an integer parameter m representing the month number of
the year and returns the corresponding name of the month. (For example, if m = 4,
month is April).
d) Write a C function (using pointer
parameters) that compares two integer arrays to see
whether they are identical. The function returns 1 if they are identical, 0 otherwise.
whether
No comments:
Post a Comment