0% found this document useful (0 votes)
419 views24 pages

Cse Programming For Problem Solving Tutorial Question Bank

This document provides information about a computer science and engineering course on programming for problem solving at the Institute of Aeronautical Engineering. It includes the course code, structure, objectives, outcomes, faculty, and a sample tutorial question bank covering topics like data types, operators, functions, and more. The question bank contains short answer and long answer questions assessing different cognitive levels, mapped to the course outcomes and learning objectives.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
419 views24 pages

Cse Programming For Problem Solving Tutorial Question Bank

This document provides information about a computer science and engineering course on programming for problem solving at the Institute of Aeronautical Engineering. It includes the course code, structure, objectives, outcomes, faculty, and a sample tutorial question bank covering topics like data types, operators, functions, and more. The question bank contains short answer and long answer questions assessing different cognitive levels, mapped to the course outcomes and learning objectives.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 24

INSTITUTE OF AERONAUTICAL ENGINEERING

(Autonomous)
Dundigal, Hyderabad - 500 043

COMPUTER SCIENCE AND ENGINEERING

TUTORIAL QUESTION BANK

Course Title PROGRAMMING FOR PROBLEM SOLVING


Course Code ACSB01
Programme B.Tech
I AE | ME
Semester
II CSE | IT | ECE |EEE
Course Type Foundation
Regulation IARE - R18
Theory Practical
Course Structure Lectures Tutorials Credits Laboratory Credits
3 0 3 4 2
Chief Coordinator Mr. P Ravinder, Assistant Professor
Course Faculty Dr. J Sirisha Devi, Associate Professor, CSE Dept
Dr. R ObulaKonda Reddy Associate Professor , CSE Dept
Mrs. K Laxmi Narayanamma, Assistant Professor, IT Dept.
Mrs. B Padmaja Assistant Professor, CSE Dept
Dr. M Purushotham Reddy, IT Dept
Mr. Ch Suresh Kumar Raju Assistant Professor, CSE Dept.

COURSE OBJECTIVES:
The course should enable the students to:
I. Learn adequate knowledge by problem solving techniques.
II. Understand programming skills using the fundamentals and basics of C Language.
III. Improve problem solving skills using arrays, strings, and functions.
IV. Understand the dynamics of memory by pointers.
V. Study files creation process with access permissions.

COURSE OUTCOMES (COs):


CO 1 Describe the concept of computer system, analyze a given problem, develop an algorithm, fundamental
programming constructs, identify data representation formats, and describe operators and their
precedence, associativity.
CO 2 Understand decision making control statements and loop control statements.
CO 3 Describe the concept of homogeneous derives data types, strings and functions.
CO 4 Understand pointers and heterogeneous data types and its necessity.
CO 5 Describe the concept of file system, file system modes and functions.
COURSE LEARNING OUTCOMES (CLOs):
Students, who complete the course, will have demonstrated the ability to do the following:

ACSB01.01 Identify and understand the working of key components of a computer system.
ACSB01.02 Analyze a given problem and develop an algorithm to solve the problem.
ACSB01.03 Describe the fundamental programming constructs and articulate how they are used to develop a
program with a desired runtime execution flow.
ACSB01.04 Gain knowledge to identify appropriate C language constructs to write basic programs.
ACSB01.05 Identify the right data representation formats based on the requirements of the problem.
ACSB01.06 Describe the operators, their precedence and associativity while evaluating expressions in program
statements.
ACSB01.07 Understand branching statements, loop statements and use them in problem solving.
ACSB01.08 Learn homogenous derived data types and use them to solve statistical problems.
ACSB01.09 Identify the right string function to write string programs.
ACSB01.10 Understand procedural oriented programming using functions.
ACSB01.11 Understand how recursion works and write programs using recursion to solve problems.
ACSB01.12 Differentiate call by value and call by reference parameter passing mechanisms.
ACSB01.13 Understand storage classes and preprocessor directives for programming
ACSB01.14 Understand pointers conceptually and apply them in C programs.
ACSB01.15 Distinguish homogenous and heterogeneous data types and apply them in solving data processing
applications.
ACSB01.16 Explain the concept of file system for handling data storage and apply it for solving problems
ACSB01.17 Differentiate text files and binary files and write the simple C programs using file handling
functions.
ACSB01.18 Identify the right string function to write string programs.
ACSB01.19 Understand procedural oriented programming using functions.
ACSB01.20 Understand how recursion works and write programs using recursion to solve problems.
TUTORIAL QUESTION BANK
MODULE - I
INTRODUCTION
Part - A (Short Answer Questions)
S No Questions Blooms Course Course
Taxonomy Outcomes Learning
Level Outcomes
(CLOs)
1 List the two major components of a computer system? Remember CO 1 ACSB01.01
2 Identify the steps in creating and running a C program? Remember CO 1 ACSB01.03
3 What are the different types of computing environments? Remember CO 1 ACSB01.02
4 Define a flowchart and the symbols used in it? Understand CO 1 ACSB01.03
5 State the properties of an algorithm? Remember CO 1 ACSB01.02
6 List out the generations of computers? Understand CO 1 ACSB01.02
7 What are the different types of computer programming languages? Understand CO 1 ACSB01.02
8 Write the various classes of data types ANSI C supports? Remember CO 1 ACSB01.05
9 State which of the following are valid identifiers. If invalid, state the Understand CO 1 ACSB01.05
reason.
1. sample1
2. data_7 return
3. #fine 91-080-100
4. name &age
5. _val
10 What are the C tokens? Remember CO 1 ACSB01.05
11 List out the rules for identifiers? Remember CO 1 ACSB01.05
12 What is type casting and list its types? Understand CO 1 ACSB01.05
13 Write the basic structure of a C program? Understand CO 1 ACSB01.05
14 Define ternary or conditional operator with an example? Understand CO 1 ACSB01.06
15 Find the value of x in the following expression? x = 3 / 2 % 6 – 3 / 9; Understand CO 1 ACSB01.06
16 List out the bit-wise operators in C? Understand CO 1 ACSB01.05
17 Write the size and range of the fundamental data types? Remember CO 1 ACSB01.05
18 Explain the various key words related to data types and loops? Remember CO 1 ACSB01.04
19 List out logical operators used in C language? Understand CO 1 ACSB01.06
20 Write the basic escape sequence characters and its meaning with Remember CO 1 ACSB01.06
example?
Part - B (Long Answer Questions)
1 Explain the fundamental data types along with its size and range? Understand CO 1 ACSB01.03
2 Explain bit-wise operators with example? Understand CO 1 ACSB01.05
3 Explain the following functions with example? Understand CO 1 ACSB01.06
i. getc()
ii. putc()
iii. gets()
iv. puts()
4 Explain the salient features and applications of C language? Understand CO 1 ACSB01.05
5 Explain the modifiers used for data types in C language? Understand CO 1 ACSB01.06
6 Explain type conversions in C with example? Understand CO 1 ACSB01.06
7 Find the output of the following expression step by step by Remember CO 1 ACSB01.05
mentioning operator precedence and associativity in each step
17 – 8 / 4 * 2 + 3 - ++5
8 Write a C program to find the size of primary data types using size of Understand CO 1 ACSB01.06
operator?
9 Write a C program to calculate the area of a sphere where A = 4πr 2 by Understand CO 1 ACSB01.04
taking radius as input from the user?
10 Write a C program to read the temperature in Fahrenheit and convert it Understand CO 1 ACSB01.06
Into Celsius by using the formula C = (F − 32) × 5/9
11 Explain the special operators in C with example? Understand CO 1 ACSB01.05
12 Write a C program to find the area of a Circle and also draw a Understand CO 1 ACSB01.04
flowchart for it?
13 Write a C program to swap two numbers with and without using a Understand CO 1 ACSB01.06
third variable?
14 Write a C program to calculate the sum of N natural numbers without Understand CO 1 ACSB01.05
using a loop?
15 Draw a flowchart to find the factorial of a given number? Understand CO 1 ACSB01.06
16 Write a C program to find the volume of a Cone by reading the inputs Understand CO 1 ACSB01.05
radius and height from the user where V = πr2 (h /3)
17 The price of one kg of Rice is Rs. 40.75 and one kg of Dal is Rs. 72.50. Understand CO 1 ACSB01.04
Write a C program to get these values from the user and display the
prices as follows:
**** LIST OF ITEMS ****
*** Item Price ***
Rice Rs 40.75
Sugar Rs 72.50
18 Explain the various operators used in c programming and exemplify the Understand CO 1 ACSB01.04
use of ternary operator
19 Distance between two points (x1, y1) and (x2, y2) is governed by the Understand CO 1 ACSB01.04
formula D2 = (x2 – x1)2 + (y2 – y1)2
Write a C program to compute D given the coordinates of the points.
20 The total distance travelled by a vehicle in t seconds is given by Understand CO 1 ACSB01.04
distance = ut+ (at2)/2 Where u is the initial velocity (meters per
second), a is the acceleration (meters per second).
Write a C program to calculate the distance travelled, given the
values of u and a.
Part - C (Problem Solving and Critical Thinking Questions)
1 What does the following statement do, justify your answer? x = x |1 << Understand CO 1 ACSB01.05
n;
i. Sets x as2n
ii. Sets (n+1)thbit ofx
iii. Toggles (n+1)thbit ofx
iv. Unsets (n+1)thbit ofx
2 #include Understand CO 1 ACSB01.05
<stdio.h>
int
main(voi
d)
{
int a = 1; int b = 0;
b = a++ + a++; printf("%d %d",a,b); return 0;
}
i. 36
ii. Compiler Dependent
iii. 3 4
iv. 3 3
3 What is the output of following program? Understand CO 1 ACSB01.05
int main()
{
int a = 1; int b = 1;
int c = a || --b;
int d = a-- && --b;
printf("a = %d, b = %d, c = %d, d = %d", a,
b, c, d); return 0;
}
4 Predict the output of the below program: Understand CO 1 ACSB01.06
int main()
{
printf("%d", 1 << 2 + 3 << 4);
return 0;
}
5 Predict the output of following program? Understand CO 1 ACSB01.06
int main()
{
int x = 10; int y = 20;
x += y += 10;
printf (" %d
%d", x, y);
return 0;
}
6 Predict the output of following program? Understand CO 1 ACSB01.05
int main()
{
int a = 0; int b;
a = (a == (a == 1));
printf(
"%d",
a);
return
0;
}
7 Predict the output of following program? Understand CO 1 ACSB01.06
int main()
{
int y = 0;
int x = (~y == 1); printf("%d", x);
return 0;
}
8 Predict the output of following program? Understand CO 1 ACSB01.06
int main()
{
int a = 2,b = 5; a =a^b;
b =b^a;
printf("%d
%d",a,b);
return0;
}
9 What is the output of the program? Understand CO 1 ACSB01.06
int main()
{int x = 10, y = 20, z = 5, i; i = x
< y < z;
printf("%d\n", i);
return 0;
10 What is the output of the program Understand CO 1 ACSB01.04
int main()
{
int X=40;
{
int X=20;
printf("%d ", X);
}printf("% d\n", X);
Return 0;
}
MODULE - II
CONTROL STRUCTURES
Part - A (Short Answer Questions)
1 What is a control structure? List out their types. Understand CO 2 ACSB01.07
2 Write a C program to check whether number is Prime or Not Understand CO 2 ACSB01.07
3 What is the difference between while loop and do-while loop Understand CO 2 ACSB01.07
4 Write a C program to check whether a number is positive or negative. Understand CO 2 ACSB01.07
5 Find the output of the following code? Understand CO 2 ACSB01.07
int main()
{
int i = 1;
for(; i< 4; i++);
printf("%d", i); return 0;
}
6 What is nested for and write the syntax of nested for loop. Understand CO 2 ACSB01.07
7 Find the output of the following code? Understand CO 2 ACSB01.07
int main()
{
int a;
for(a = 5; --a;)
printf("\n%d", a); return 0;
}
8 State the difference between entry controlled and exit controlled loop Remember CO 2 ACSB01.07
with example?
9 Write the usage of break and continue statement with example? Remember CO 2 ACSB01.07
10 Find the output of the following code? Understand CO 2 ACSB01.07
int main()
{
int a = 1, b = 2, c = 3, d =
4, e; if(e= (a & b | c ^ d))
printf("%d", e); return 0;
}
11 Find the output of the following code? Understand CO 2 ACSB01.07
int main()
{
int a=1,b=2,c=3,d=4; if (d > c)
if (c > b)
printf("%d %d", d, c); else if (c > a)
printf("%d %d", c, d);
if (c > a)
if (b < a)
printf("%d %d", c, a); else if (b < c)
printf("%d %d", b, c);
}
12 Find the output of the following code? Understand CO 2 ACSB01.07
void main()
{
int choice = 3;
switch(choice)
{
default: printf("default");
case 1: printf("choice 1");break;
case 2: printf("choice 2");break;
}
}
13 Find the output of the following code? Understand CO 2 ACSB01.07
void main()
{
char c = 125; do
printf("\n%d", c); while(c++);
}
14 Find the output of the following code? Understand CO 2 ACSB01.07
void main()
{
for(;;)
{
printf("%d", 10);
}
}
15 Find the output of the following code? Understand CO 2 ACSB01.07
void main()
{
printf("hi!"); if (!0)
printf("bye");
}
16 Find the output of the following code? Understand CO 2 ACSB01.07
void main()
{
int a =1; if(a)
printf("test"); else ; printf("again");
}
17 Find the output of the following code? Understand CO 2 ACSB01.07
void main()
{
int i =1;
if(i++, ++i, i--, --i)
printf(“%d\n”, i);
}
18 Find the output of the following code? Understand CO 2 ACSB01.07
void main()
{
float i;
for(i = 0.1;i < 0.4; i += 0.1)
printf("%.1f\n", i);
}
19 Explain with example switch case execution process with and without Understand CO 2 ACSB01.07
break statement?
20 Find the output of the following code? Understand CO 2 ACSB01.07
void main()
{
int i = 3;
for(i--; i< 7; i = 7)
printf("%d", i++);
}
Part - B (Long Answer Questions)
1 Compare and Contrast while and do while loop? Write a C program to Remember CO 2 ACSB01.07
print the odd numbers from X to Y using do while loop?
2 An electric power distribution company charges domestic consumers Understand CO 2 ACSB01.07
as follows:
Consumption Units Rate ofcharge
0-20 Rs 0.50 perunit
201-400 Rs 100 + Rs0.65 per unit excessof200
401-600 Rs 230 plus 0.80 per unit excessof400
601andabove Rs 390 plus Rs 1.00 per unit excess
of600 Write a C program that reads the customer number and
power consumed and print amount to be paid by the customer
(Use else-if ladder)
3 Write a C program to display the traffic control signal lights based on Understand CO 2 ACSB01.07
the following.
i. If user entered character is R or r then print RED Light
Please STOP.
ii. If user entered character is Y or y then print
YELLOW Light Please Check and Go.
iii. If user entered character is G or g then print GREEN Light
Please GO.
iv. If user entered some other character then print THERE IS
NOSIGNAL POINT.
4 Admission to a professional course is subject to the following Understand CO 2 ACSB01.07
conditions:
i. Marks in Mathematics >=60
ii. Marks in Physics >= 50 Marks in Chemistry >=40
iii. Total in all three subjects >=200
iv. Total in Mathematics and Physics >=150
Given the marks in the three subjects, Write a C program to process
the application to list the eligible candidates.
5 Write a C program to compute the real roots of a quadratic equation Understand CO 2 ACSB01.07
ax2 + bx+ c = 0. The program should request for the values of the
constants a, b and c and print the values of x1 and x2.
Use the following rules:
i. No solution, if both a and b are zero There is only one root, ifa=0
ii. There are no real roots, if b2 - 4ac is negative
Otherwise, there are two real roots
Write a C program to test all the above conditions.
6 Write a program that counts from one to ten, prints the values on a Understand CO 2 ACSB01.07
separate line for each, and includes a message of your choice when the
count is 3 and a different message when the count is 7.
7 Write a C program to calculate commission for the input value of Understand CO 2 ACSB01.07
sales amount. Commission is calculated as per the following rules:
i. Commission is nil for sales amount Rs5000/.
ii. Commission is 2% for sales when sales amount is greater than
5000and less than equal to10000.
iii. Commission is 5% for sales amount greater than10000.
8 A character is entered through keyboard. Write a C program to Understand CO 2 ACSB01.07
determine whether the character entered is a capital letter, a small case
letter, a digit or a special symbol using if-else and switch case. The
following table shows the range of ASCII values for various
characters.
Characters ASC

II values A–Z 65 –90


a–z 97 –122
0–9 48 – 57
Special symbols 0 – 47, 58 – 64, 91 – 96, 123 -127
9 If cost price and selling price of an item S input through the keyboard, Understand CO 2 ACSB01.07
write a program to determine whether the seller has made profit or
incurred loss.
Write a C program to determine how much profit or loss incurred in
percentage.
10 Write a C program to produce the following output? Understand CO 2 ACSB01.07
1
3 5
7 9 11
13 15 17 19
11 Write a C program for the following: Understand CO 2 ACSB01.07
i. To print the reverse of an integer number
ii. To check whether the given integer is palindrome or not.
12 Write a C program to print the numbers in triangular form. Understand CO 2 ACSB01.07
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
13 Write a C program to read in two numbers, x and n, and then compute Understand CO 2 ACSB01.07
the sum of this geometric progression1+x+x2+x3+...xn. For example: if
n is 3 and x is 5, then the program computes 1+5+25+125. Print x, n,
the sum. Perform error checking. For example the formula does not
make sense for negative Exponents – if n is less than 0.
Have your program print an error message if n<0,then go back and read
in then pair of numbers of without computing the sum. Are any values
of x also illegal? If so, test for them too.
14 Write a C program to print Armstrong numbers between 1 to n where Understand CO 2 ACSB01.07
n value is entered by the user.
[Hint: Armstrong number is defined as the sum of cubes of individual
digits of a number. e.g. 371 = 33 + 73 + 13 ]
15 Write a C program to generate all prime numbers between 1 and n, Understand CO 2 ACSB01.07
where n value is supplied by the user.
16 Write a C program to print first n lines of the Pascal”s Understand CO 2 ACSB01.07
Triangle.Pascal”s triangle is a triangular array of the binomial
coefficients.
1
1 1
1 2 1
1 3 3 1
17 Write a C program to print first n lines of Floyd‟s Triangle. Understand CO 2 ACSB01.07
1
2 3
4 5 6
7 8 9 10
18 Write a C program to print the following series Understand CO 2 ACSB01.07
1/1! + 2/2! + 3/3! + ……………
19 Write a C program to compute and display the sum of all integers that Understand CO 2 ACSB01.07
are divisible by 6 but not divisible by 4 and lie between 0 and 100.
The program should also count and display the number of such values.
20 Write a C program to find the LCM and GCD of two integers? Understand CO 2 ACSB01.07
Part - C (Problem Solving and Critical Thinking Questions)
1 Predict the output of the following? Understand CO 2 ACSB01.07
int main()
{
int i = 1024;
for (; i; i >>= 1)
printf("IARE");
return 0;
}

2 Find the final value of i, j, k from the code? Understand CO 2 ACSB01.07


void main()
{
int i = 5, j = 10, k = 1; if(++i || ++j )
k = i + j;
else
k = i - j; printf("%3d%3d%3d", i, j, k);
}
3 Predict the output of the following? Understand CO 2 ACSB01.07
void main()
{
int i, j, k;
for(i = 1;i < 3; i++)
{
for( j = 1; j < 3; j++)
{
for(k = 1; k < 3; k++)
{
if(j == k) break; else
{
printf("%d\t%d\t%d\n", i,j, k);
continue;
}
}
}
}
}
4 Find the error from the code given below: Understand CO 2 ACSB01.07
int main()
{
char check = 'a';
switch(check)
{
case 'a' || 1: printf("IARE"); case 'b' || 2:
printf("IIT");break; default:printf("IARE-IIT");
}
return 0;
}
5 Predict how many times IARE will be printed: Understand CO 2 ACSB01.07
int main()
{
int i = -5; while(i<=5)
{
if(i>=0)
break;
else
{
i++;
continue;
}
printf("IARE");
}
return 0;
}
Output:
i. 0 ii 10 iii 5 iv 3
6 Predict the output of the following? Understand CO 2 ACSB01.07
int main()
{
int i = 3; while (i--)
{
int i = 100; i--;
printf("%d ", i);
}
return 0;
}
7 Find the combination of the integer variables x, y and z makes the Understand CO 2 ACSB01.07
variable a get the value 4 in the following expression?
a = ( x > y ) ? (( x > z ) ? x : z) : (( y > z ) ? y : z )

i. x = 3, y = 4, z =2
ii. x = 6, y = 5, z =3
iii. x = 6, y = 3, z =5
iv. iv. x = 5, y = 4, z =5
8 Predict the output of the following: Understand CO 2 ACSB01.07
int main()
{
int i;
goto LOOP;
for(i = 0 ; i< 10 ; i++)
{
printf("IARE\n"); LOOP:break;
}
return 0;
}
9 Predict the output of the following: Understand CO 2 ACSB01.07
int main()
{
unsigned short int i = 65000; while(i++ != 0);
printf("ans : %d", i); return 0;
}
10 Predict the output of the following: Understand CO 2 ACSB01.07

#include<stdio.h>

int main()
{
int i = 65; char j='A'; while(i< j);
printf(" %d", (i ^ j )<< 2); return 0;
}

MODULE – III
ARRAYS AND FUNCTIONS
Part - A (Short Answer Questions)
1 What is an array and write the syntax to declare an array. Remember CO 3 ACSB01.08
2 State which of the following multi-dimensional array declaration is Understand CO 3 ACSB01.08
correct for realizing a 2x3 matrix?
int m[2][3];
int m[3][2];
int m[3],m[2];
3 Find the output of the following code? Understand CO 3 ACSB01.08
void main(){
int a[3][2] = {10, 20, 30, 40, 50, 60};
printf("%d", a[0][4]);
}
4 Find the output of the following code? Understand CO 3 ACSB01.09
void main()
{
char s1[] = "jaihind"; char s2[] ="jaipur"; int x;
x =strncmp(s1,s2,3); printf("x = %d", x);
}
5 Find the output of the following code? Understand CO 3 ACSB01.09
void main()
{
char s1[] = "NEW DELHI"; char s2[] ="BANGALORE";
strncpy(s1,s2,4); printf("%s", s1);
}
6 Identify which of the following is used to Remember CO 3 ACSB01.08
represent the end of a string?
i. Blankspace
ii. Nullcharacter
iii. Newlinecharacter
iv. Last element of thestring
7 Identify the string function used to find the sub- string in the main Remember CO 3 ACSB01.09
string and also write it‟s syntax?
8 Find the output of the following code? Understand CO 3 ACSB01.09
void main()
{
char s1[] = "NEW DELHI";
char s2[] ="NEW";
printf("%d",strstr(s1,s2));
}
9 Find the output of the following code? Understand CO 3 ACSB01.08
void main()
{
int a[4][3];
printf("%d",sizeof(a));
}
10 Write the syntax for strcat() and strncat() with example? Remember CO 3 ACSB01.09

11 Find the output of the following code? Understand CO 3 ACSB01.08


void main()
{
int i, j, a[][3]= {{1,2,3}, {4,5,6}};
for(i=0; i< 2; i++)
{
for(j=0; j < 3;j++)
printf("%5d", a[i][j]); printf("\n");
}
}
12 Write various methods of character array initialization with example? Remember CO 3 ACSB01.08
13 Write the syntax with example for the following string functions: Remember CO 3 ACSB01.09
i. strcmp()
ii. strrev()
14 Write the syntax and initialization procedure for a three dimensional Remember CO 3 ACSB01.08
array?
15 Find the output of the following code? Understand CO 3 ACSB01.08
void main()
{
int i, j, k;
int
a[][3][3]={{1,2,3,4,5,6,7,8,9},{10,11,12,13,14,15,16,17,18}};
for(i=0; i< 2; i++)
{
for(j=0; j < 3;j++)
{
for(k=0; k < 3;k++)
{
printf("%5d", a[i][j][k]);
}
printf("\n");
}
printf("\n");
}
}
16 What is the use of functions in programming? Understand CO 3 ACSB01.10
17 What is the syntax of a function, define some of the predefined Understand CO 3 ACSB01.10
Functions
18 What is the difference between normal function and recursive function. Understand CO 3 ACSB01.11
19 Describe various parameter passing method. Remember CO 3 ACSB01.12
20 State the need for dynamic memory allocation and how does it help in Remember CO 3 ACSB01.12
building complex programs?
Part - B (Long Answer Questions)
1 Define an array and explain the process of array initialization with Understand CO 3 ACSB01.08
example?
2 Write C programs to find the largest and smallest number among a list Understand CO 3 ACSB01.08
of integers.
3 Write C program to read a list of elements into an array and print the Understand CO 3 ACSB01.08
reverse of the list.
4 Write C programs to read two matrices and find the addition Understand CO 3 ACSB01.08
and multiplication of two matrices.
5 Write C programs to find the transpose of a matrix. Understand CO 3 ACSB01.08
e.g. Given matrix 1 2 3
4 5 6
Transpose of the matrix:
1 4
2 5
3 6
6 Write a C program to store numbers into an array and find the Understand CO 3 ACSB01.08
frequency of a particular number in array and print it.
7 Write a C program to copy the string str2 into str1 without using Understand CO 3 ACSB01.09
strcpy() function.
8 Write a C program to check whether a string is palindrome or not Understand CO 3 ACSB01.09
without using string function.
9 Write a C program to read your email id and print the number of Understand CO 3 ACSB01.09
vowels, consonants and special characters in it.
10 Write a C program to insert a sub-string in to given main string at a Understand CO 3 ACSB01.09
given position without using string functions.

11 Write a C program to read a lowercase string and convert it into Understand CO 3 ACSB01.09
uppercase.
12 Write a C program to accept two strings and compare them. It should Understand CO 3 ACSB01.09
print
whether both are equal or first string is greater than the second or the
first string is less than the second string.
13 Write a C program to read N unsorted integers and sort them in Understand CO 3 ACSB01.08
ascending order.
14 Explain the following string handling functions with example: Understand CO 3 ACSB01.09
i. strcpy()
ii. strcat()
iii. strrev()
iv. strcmp()
v. strupr()
15 Write a C program to add a string at the end of another string and Understand CO 3 ACSB01.09
display the output.
char a[20] = “hello”; char b[10] = “World”;
Output:
“HelloWorld”
16 Write C programs that uses both recursive and non-recursive Understand CO 3 ACSB01.10
functions:
a. Find the sum of n natural numbers
b. Find the factorial of a given number
17 Write a C program that uses functions to do the following: Understand CO 3 ACSB01.11
a. Convert decimal number to binary number
b. Convert binary number to decimal number
18 Write C programs that uses both recursive and non-recursive Understand CO 3 ACSB01.10
functions:
a. Find the Nth Fibonacci number
b. Find the reverse of a number
19 Write a C program that uses functions to do the following: Understand CO 3 ACSB01.10
a. Convert a Roman letter into its decimal equivalent.
b. Find 2‟s complement of a binary number.
20 Write a user defined function which takes an array of sorted integers Understand CO 3 ACSB01.10
and returns the median value?
[Hint: For odd set of integers there will be a single median and for
even set of integers, there will be two middle values and median is
the average of the two middle values]
Part - C (Problem Solving and Critical Thinking Questions)
1 Predict the output of the following code? Understand CO 3 ACSB01.08
int main()
{
int arr1[]={97, 98, 99, 100, 101, 102, 103, 104, 105};
int i=0; while(i++ < 5)
printf("\n %c ", arr1[i++]); return 0;
}
2 Find the output of the following code? Understand CO 3 ACSB01.08
void main()
{
int a[3] = {10, 20, 30};
a[2] = 2;
a[2 -2] = 2;
printf("%d\t%d\t%d", a[0], a[1], a[2]);
}
3 Find the output of the following code? Understand CO 3 ACSB01.08
void main()
{
char a[5] = "IARE"; int i =0;
while(a[i])
printf("%s\n", (a + i++)); }
4 Find error if any: Understand CO 3 ACSB01.08
Void main()
{
int x =5;
int a[x]; a[1] = 12;
printf(“%d”, a[1]);
}
5 Find the output of the following code? Understand CO 3 ACSB01.08
void main()
{
int x[5] = {1, 2, 3, 4, 5};
int i;
for(i = 0; i< 20; i++) printf(“%d\n”, x[i]);
}

6 Find the output of the following code? Understand CO 3 ACSB01.09


void main()
{
char s1[10] = “abc”; char s2[] = “abc”; if(s1 == s2)
printf(“yes both strings are
same”); else
printf(“no both are different”);
}
7 Find the output of the following code? Understand CO 3 ACSB01.09
void main()
{
char s1[10] = “abc”; char s2[20];
s2 = s1;
printf(“
%s”, s2);
}
8 Find the output of the following code? Understand CO 3 ACSB01.09
void main()
{
char s[] = “hello”;
int i = 0, n = strlen(s); while(n)
{
n--;
s[i] = s[n]; i++;
}
printf(“%s”, s);
}
9 Find the output of the following code? Understand CO 3 ACSB01.08
void main()
{
char s[20]; int i;
for(i=0; i< 3;i++) i[s] = „x‟;
i[s] =‟\0‟; puts(s);}
10 Predict the output of the following code? Understand CO 3 ACSB01.08
void main()
{
int a1[10], a2[10];
int i;
for(i=1; i<=9; i++)
{ a1[i] = 'A' + i;
a2[i] = 'a' + i;
printf("%d\n",
a2[i] -a1[i]);
}
}
MODULE - IV
STRUCTURES, UNIONS AND POINTERS
Part - A (Short Answer Questions)
1 Define a structure and state how the members of a structure are Remember CO 4 ACSB01.15
accessed with example?
2 Write the major differences between arrays and structures? Remember CO 4 ACSB01.15
3 Write an example of nested structure? Remember CO 4 ACSB01.15
4 State the difference between a structure and union? Remember CO 4 ACSB01.15
5 Write an example of array of structures? Remember CO 4 ACSB01.15
6 Write the general format of sending a copy of a structure to the called CO 4 ACSB01.15
Function? Remember
7 Describe the difference between Structure and Union Remember CO 4 ACSB01.15
8 Describe the syntax of nested structure Remember CO 4 ACSB01.15
9 Find the output of the following? Understand CO 4 ACSB01.15
struct
{
int i; float f;
}var;
void main()
{
var.i=5; var.f=9.76723;
printf("%d %.2f",var.i,var.f);
}
10 Write the output of the following? Understand CO 4 ACSB01.15
#include<stdio.h>
struct values
{
int i;
float f;
};
void main()
{
struct values
var={555,67.05501};
printf("%2d%.2f",var.i,var.f);
}
11 Write the output of the following? Understand CO 4 ACSB01.15
union A
{
char ch; int i; float f;
}temp; voidmain()
{
temp.ch='A';
temp.i=777;
temp.f=12345.12345;
printf("%d", temp.i);
}
12 Write the output of the following? Understand CO 4 ACSB01.15
void main()
{
struct employee
{
unsigned id: 8; unsigned sex:1;
unsigned age:7;
};
struct employee emp1={203,1,23};
printf("%d\t%d\t%d",emp1.id,emp1.sex,emp1.age);
}
13 Write an example for enumerated data type? Remember CO 4 ACSB01.15
14 State the default starting value of enumerated set? Remember CO 4 ACSB01.15
15 Write the usage of typedef with example? Remember CO 4 ACSB01.15
16 Write the value of tulip from the following enumerated flowers? enum Remember CO 4 ACSB01.15
flowers{rose, lily = 5, lotus, tulip, sunflower);
17 State the operator which connects the structure name to its member Remember CO 4 ACSB01.15
name?
18 Consider the following C declaration Remember CO 4 ACSB01.15
struct {
short s[5];
union {
float y; long z;
}u;
} t;
Assume that objects of the type short float and long occupy 2
bytes, 4 bytes and 8 bytes, respectively.
19 Differentiate between structure and union with regard to memory Understand CO 4 ACSB01.15
allocation.
20 Predict the output of following C program Understand CO 4 ACSB01.15
#include<stdio.h>
struct Point
{
int x, y,z;
};
intmain()
{
struct Point p1 = {.y = 0, .z =
1, .x =2}; printf("%d %d %d",
p1.x, p1.y, p1.z); return0;
}
Part - B (Long Answer Questions)
1 Write a C program to read your full name, Date of birth and display Understand CO 4 ACSB01.15
the same using the concept of nested structure.
2 Write a C program to maintain a book structure containing name, Understand CO 4 ACSB01.15
author and pages as structure members. Pass the address of structure
variable to a user defined function and display the contents.
3 A marketing company is having 50 employees and it maintains Understand CO 4 ACSB01.15
employee records in terms of their empid, empname, desg, salary,
quantity, sales amount. The company gives 10% hike in salary to the
employees if their sales amount is more than 50000/-. Write a C
program that displays the employee records who got hike in salary.
4 IARE College is maintaining student attendance records by storing Understand CO 4 ACSB01.15
rollno, stdname, attendance percentage in 5 different subjects.
Write a C program using structures to find the average attendance
percentage and print the following
a. If attendance percentage >=75 then print student is eligible for
writing final exam.
b. If attendance percentage >= 65 and <75 then print
studentisincondonationlist.
c. Otherwise not eligible for writingexams.
5 Consider the declaration of the Understand CO 4 ACSB01.15
structure typedef struct
{
char x; char *y; int z[20];
} status;
Discuss whether the following are valid, if invalid, give reason.
a. struct statuss1;
b. struct statuss2[25];
c. statuss3;
d. status s4[20];
6 Compare and Explain the following with suitable examples: Understand CO 4 ACSB01.15
a. Nested Structures
b. Array ofstructures
7 Explain the following with suitable example: Remember CO 4 ACSB01.15
a. self referential structures
b. enumerated types
8 Write a C program to pass a copy of the entire structure named Understand CO 4 ACSB01.15
stores containing members product-name, price and quantity to a
function?
9 Compare Unions and Structures .Explain the differences with Remember CO 4 ACSB01.15
examples.
10 What are different ways of assigning values to structure members? Remember CO 4 ACSB01.15
Explain each method with examples.
11 Explain three different approaches that can be used to pass structures Remember CO 4 ACSB01.15
as function arguments. Illustrate each of them with suitable example.
12 Define a structure called complex consisting of two floating point Understand CO 4 ACSB01.15
numbers x and y and declare a variable p of type complex. Assign
initial values 0.0 and 1.1 to the members.
13 Define a structure data type called time_struct containing 3 Understand CO 4 ACSB01.15
members integer hour, integer minute and integer second. Develop a
program that would assign values to the individual members and
display the time in the following format:16 : 40 : 51
14 Define a structure named census with the following 3 members: Understand CO 4 ACSB01.15
a. A character array city[ ] to store names.
b. A long integer to store population of the city.
c. A float member to store the literacy level.
Write a program to do the following:
d. To read details for 5 cities randomly using an array variable.
e. To sort the list alphabetically.
f. To sort the list based on literacy level.
g. To sort the list based on population.
c. To display sorted lists.
15 Define a structure that can describe a hotel. It should have Understand CO 4 ACSB01.15
members that include the name, address, grade, average room
charge, and number of rooms. Write functions to perform the
following operations:
a. To print out hotels of a given grade in order of charges.
b. To print out hotels with room charges less than a given value.
16 Define a structure called cricket that will describe the following Understand CO 4 ACSB01.15
information: Player name ,Team name ,Batting average using cricket,
declare an array play program to read the information about all the 50
players and print a team-wise with their batting average.
17 Define a slackbyte‟? Explain how it affects the implementation of Remember CO 4 ACSB01.15
structures through sample code.
18 Explain the meaning and purpose of the following: Understand CO 4 ACSB01.15
a. struct keyword
b. Typedef keyword
c. Sizeof operator
19 Compare and contrast structures and unions. Write a C program Understand CO 4 ACSB01.15
to maintain a record of „n‟ student details using an array of
structures with four fields(rollno,name,marks and grade).
Assume appropriate data type for each field. Print the marks of
the student name as input.
20 IARE maintains salary details of every employee by storing their Understand CO 4 ACSB01.15
name, department, basic pay, da, hra and cca. Store this information
in a nested structure and display the salary of an employee.
Part - C (Problem Solving and Critical Thinking Questions)
1 Analyze the following program and find out the error in the program? Understand CO 4 ACSB01.15
#include<stdio.h>
int main()
{
struct a
{
float category:5; char scheme:4;
};
printf("size=%d", sizeof(struct a));
return 0; }
2 Predict the output of the program? Understand CO 4 ACSB01.15
#include<stdio.h> int main()
{
struct value
{
int bit1:1; int bit3:4; int bit4:4;
}bit={1, 2, 13};
printf("%d, %d, %d\n", bit.bit1, bit.bit3, bit.bit4);
return 0;
}
3 Verify the following statements which correctly assigns 12 to month Understand CO 4 ACSB01.15
using pointer variable pdt?
#include<std io.h>
struct date
{
int day;
int month; int year;
};
int main()
{
struct date d; struct date*pdt; pdt = &d; return0;
}
4 Predict the output of the program? Understand CO 4 ACSB01.15
#include<stdio.h>
int main()
{
enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};
printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU,
FRI,SAT);
return 0;
}
5 Analyze the program and identify the error in the program? Understand CO 4 ACSB01.15
#include<stdio.h>
int main()
{
struct emp
{
char name[25]; intage;
floatbs;
};
struct emp e; e.name = “suresh”; e.age = 25;
printf(“%s %d\n”,
e.name, e.age); return 0;
}
6 Analyze the code and identify the statements which are correct in the Understand CO 4 ACSB01.15
following program?
#include<stdio.h>
int main()
{
union a
{
int i;
char ch[2];
};
union a u1 = {512}; union a u2 = {0, 2};
return 0;
}
7 Analyze the following code and predict the output from printf() Understand CO 4 ACSB01.15
statement.
struct student
{
char *name;
};
void main()
{
struct student s, m; s.name = "st";
m = s;
printf("%s%s", s.name, m.name);
}
8 Analyze the following code and predict the output from printf() Understand CO 4 ACSB01.15
statement
Struct
{
int foo, bar;
} baz;
int *example()
{
return &baz.foo;
}
9 Analyze the following program and find the output of the program? Understand CO 4 ACSB01.14
char s[100];
char *fun(char s[])
{
static
int i =
0;
if(*s)
{
fun(s + 1);
s[i] = *s; i++;
}
returns;
}
voidmain()
{
char s[] = “sample code”; printf(“%s”,
fun(s));
}
10 Analyze the following program and find the output of the program? Understand CO 4 ACSB01.14
void main()
{
char s1[7] = “1234”, *p; p = s1 + 2;
*p = „\0‟; printf(“%s”, s1);
}
MODULE - V
FILE HANDLING AND BASICALGORITHMS
Part - A (Short Answer Questions)
1 Write the basic operations of a file? Understand CO 5 ACSB01.16
2 Write the various text file opening modes? Remember CO 5 ACSB01.17
3 State the various types of status enquiry library functions in C? Remember CO 5 ACSB01.16
4 Write the syntax and usage of ftell()? Remember CO 5 ACSB01.16
5 Write the purpose of fseek() with example? Remember CO 5 ACSB01.17
6 Write the syntax and usage of rewind()? Remember CO 5 ACSB01.17
7 Write the syntax of to open a file. Understand CO 5 ACSB01.16
8 What are files in C and what are uses? Understand CO 5 ACSB01.16
9 Find the meaning of „a‟ in the following Understand CO 5 ACSB01.16
operation? fp = fopen(“sample.txt”,“a”);
10 What are some of the library functions used to write data into files? Remember CO 5 ACSB01.17
11 Predict the output of this code? Understand CO 5 ACSB01.16
#include <stdio.h> int main()
{
FILE *fp = stdout; stderr= fp;
fprintf(stderr, "%s", "hello");
}
12 Find the output of this code? Understand CO 5 ACSB01.17
#include
<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp = stdout; int n; fprintf(fp, "%d", 45);
}
13 What are the error handling function for files in C? Remember CO 5 ACSB01.16
14 Predict the output of this code? Understand CO 5 ACSB01.17
#include
<stdio.h>
#include <string.h> int main()
{
char line[3]; fgets(line, 3, stdin);
printf("%d\n", strlen(line)); return 0;
}
15 Find the content of 'file.c' after executing the following program? Understand CO 5 ACSB01.16
#include<stdio.h>
int main()
{
FILE *fp1, *fp2; fp1=fopen("file.c", "w");
fp2=fopen("file.c", "w"); fputc('A', fp1);
fputc('B', fp2);
fclose(fp1);
fclose(fp2);
return 0;
}
16 If the file 'source.txt' contains a line "Be my friend", predict the output Understand CO 5 ACSB01.17
of below program?
#include<stdio.h >
int main()
{
FILE *fs, *ft; char c[10];
fs = fopen("source.txt", "r"); c[0] = getc(fs);
fseek(fs, 0, SEEK_END); fseek(fs,-3L, SEEK_CUR);
fgets(c, 5, fs); puts(c); return0;
}
17 Identify the error in the program? Understand CO 5 ACSB01.16
#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned char; FILE *fp;
fp=fopen("trial", "r"); if(!fp)
{
printf("Unable to open file"); exit(1);
}
fclose(fp); return 0;
}
18 Justify why fseek() should be preferred over rewind(). Remember CO 5 ACSB01.17
19 What is difference between file opening mode r+ and w+? Remember CO 5 ACSB01.17
20 What are first and second arguments of fopen ? Remember CO 5 ACSB01.16
Part - B (Long Answer Questions)
1 Write a C program to read a text file containing some paragraph. Use Understand CO 5 ACSB01.16
fseek()functionandreadthetextafterskipping„n‟charactersfrombeginnin
gofthe file
2 Explain the following functions through a sample program which Understand CO 5 ACSB01.17
reads a file „test.txt‟ .
a. ftell()
b. fseek()
c. rewind()
3 Write a C program to read a text file “sample.txt” and print the Understand CO 5 ACSB01.16
following.
4 a. Substring of N characters from the positionI. CO 5
b. Reverse order of substring of N characters produced ina.
5 Write the syntax of the following file I/O functions and Explain Understand CO 5 ACSB01.16
every option in each function with suitable example :
a. fopen()
b. fclose()
c. fread()
d. fwrite()
6 Write a C program to open a file names INVENTORY and store in it Understand CO 5 ACSB01.16
the following data
Item number price quantity Printer P1
Scanner S200 5500 5
Hard disk H300 4500 8
Read the data from the INVENTORY file and display the
inventory table with the value of each item.
[Hint: value = price * quantity and use fprintf() and fscanf()
functions]
7 Write a C program to read a given file, convert first letter of each Understand CO 5 ACSB01.17
word into uppercase and copy the contents of converted file into a
new file.
8 WriteaCprogramtoreadnameandmarksof„n‟numberofstudentsfrom user Understand CO 5 ACSB01.17
and store them in a file. If the file previously exists, then add the
information of n students to the end of existing content.
9 Write a C program to print the following from a given file: Understand CO 5 ACSB01.16
1. Number of characters
2. Number of spaces
3. Number of tabs
4. Number of newlines
10 Create a structure named employee containing name, age and Understand CO 5 ACSB01.17
basic pay. Write a C program to create 5 employee records and
write to a file. Thenread the records from file and display it.
11 Write a C program to maintain a record of “n” student details using Understand CO 5 ACSB01.16
an array of structures with four fields (Roll number, Name, Marks,
and Grade). Each field is of an appropriate data type. Print the marks
of the student given student name as input.
12 Write a program to find the given element using linear searching Understand CO 5 ACSB01.17
13 Write a program to sort given array elements using insertion sort Understand CO 5 ACSB01.16
14 Define Algorithm and complexity of algorithm Remember CO 5 ACSB01.16
15 Explain the bubble sorting algorithm with an example Understand CO 5 ACSB01.17
Part - C (Problem Solving and Critical Thinking Questions)
1 In fopen(), the open mode "wx" is sometimes preferred "w" because. Understand CO 5 ACSB01.17
1) Use of wxis moreefficient.
2) If w is used, old contents of file are erased and a new
empty file is created. When wxis used, fopen() returns
NULL if file already exists.
a. Only1
b. Only2
c. Both 1 and2
d. Neither 1 and2
2 Write a C program that request for a file name and an integer known Understand CO 5 ACSB01.16
as offset value. The program then reads the file starting from the
location specified by the offset value and prints the contents on the
screen. If the offset value is a positive integer then printing skips that
many lines. If it is negative number it prints that many lines from the
end of the file. An appropriate error message should be printed if
anything goes wrong.
3 Write a menu driven C program to add, display, search, update and Understand CO 5 ACSB01.16
delete the student record. Every student record contains name, roll no,
age and marks in individual subjects.
4 Write a function that, given a binary file, copies the odd items (items Understand CO 5 ACSB01.16
1,3,5, …,n) to a second binary file and the even items (items 2,4,6, … ,
n) to a
third binary file. After all items have been copied, print the contents
of both output files.
5 Write a program in C to append multiple lines at the end of a text Understand CO 5 ACSB01.16
file. Assume that the content of the file test.txt is :test line1 test
line2 test line3 test line 4 append the lines: test line5 test line6 test
line7

Signature of the faculty HOD, CSE

You might also like