22POP13set1 Answers
22POP13set1 Answers
Model Question Paper-I with effect from 2022-23 (CBCS Scheme) - 22POP13
Step 1: Start
Step 2: Input radius
Step 3: let pi = 3.14
Step 4: area = pi * radius * radius
Step 5: perimeter = 2 * pi * radius
Step 6: print area, perimeter Step 7: stop
Algorithm: In its purest sense, an algorithm is a mathematical process to solve a problem using a finite
number of steps. In the world of computers, an algorithm is the set of instructions that defines not just
what needs to be done but how to do it. In an algorithm,
2b. Draw a flowchart and C program which takes as input p,t,r. Compute the simple interest
and display the result
2c. Write a note on the following operators. i) Relational ii) Logical iii) Conditional
i) Relational: Relational operators in C are commonly used to check the relationship between the
two variables.
ii) Logical : These operators are used to perform logical operations on the given expressions.
iii) Conditional: The conditional operator is also known as a ternary operator. The conditional
statements are the decision-making statements which depends upon the output of the expression. It is
represented by two symbols, i.e., '?' and ':'.
3a. Develop a C program that takes three coefficients (a, b, and c) of a quadratic
equation;(ax2+bx+c) as input and compute all possible roots and print them with appropriate
messages.
If the label statement is below the goto statement then it is called forward jump. if the label statement
is above the goto statement then it is called backward jump.
3c. Explain switch statement with syntax and example
A switch statement tests the value of a variable and compares it with multiple cases. Once the case
match is found, a block of statements associated with that particular case is executed. Each case in a
block of a switch has a different name/number which is referred to as an identifier. The value provided
by the user is compared with all the cases inside the switch block until the match is found. If a case
match is not found, then the default statement is executed, and the control goes out of the switch block.
The break statement is used at the end of each case to come out of the switch block.
4a. Develop a simple calculator program in C language to do simple operations like addition,
subtraction, multiplication and division. Use switch statement in your program
(ii) if-else statement: This is a two way selection statement which executes true block or false block
of statements based on the given condition. The keyword “else” is used to shift the control when
the condition is evaluated to false.
Syntax: if(conditional_expression) { } else { } True block statements; False block statements;
5a. Write a C program to swapping of 2 numbers using call by reference and call by value.
Call by value. Call by reference
5c. Discuss the implementation of user defined function with suitable example.
The user defined function is defined by the user according to its requirements instead of relying
only on the built-in functions C allows us to create our own function called user defined function.
Parts of user defined function. (i)Function Declaration or Function prototype (ii)Function call or
calling Function (iii)Function Definition or defining a function.
i)Function Declaration or Function prototype :- It will inform the compiler about the return type,
function name and number of arguments along with the data types.
syntax: return_type function_name(argument _list);
ii) Function call or calling function :- invoking the function with valid number of arguments and
valid data type is called as function call.
Syntax: function_name(argumement_list);
iii) Function definition or defining a function :- The declared function must define the same to
perform the specific task.
6b. Explain the declaration and initialization of one dimensional and two dimensional arrays with
an example.
Single Dimensional Array :- An Array which has only one subscript is known as Single
dimensional array or One dimensional array The individual array elements are processed by using
a common array name with different index values that start with Zero and ends with array_size-1.
Syntax of Declaring Single Dimensional Arrays: data_type array_name[array_size];
where data_type: can be int, float or char array_name: is name of the array
array_size : an integer constant indicating the maximum number of data elements to be stored.
Example: int a[5];
The general syntax of initialization of array is
data_type array_name[array_size]= {List of values};
Example: int b[4]={10,12,14,16};
Here each value will be stored in respective index values of the array.
Two dimensional array: The simplest form of multidimensional array is two dimensional array.
Arrays with two or more dimensions are called multi-dimensional arrays. (in terms of rows and
columns) of same data type or An array which has two subscripts are known as two dimensional
arrays.
The first subscript represents rows and the second subscript represent column.
7b. Define String. Explain any 4 string manipulation function with suitable example.
String constant or a string literal can be defined as a sequence of characters enclosed in
double quotes that will be treated as a single data element followed by a null character ‘\0’
(Null character indicates the end of string)
1.
2.
3.
4.
8a. Develop a C program to find the largest of three numbers using pointer.
8b. Define Pointer. Explain pointer variable declaration and initialization with suitable example.
The pointers in C language refer to the variables that hold the addresses of different variables of similar
data types. • We use pointers to access the memory of the said variable and then manipulate their
addresses in a program.
Declaration of a pointer is done before using it to store any variable address.
The general form of a pointer variable declaration is − type *var-name; type is the pointer's base type;
it must be a valid C data type and var-name is the name of the pointer variable.
The asterisk * used to declare a pointer is the same asterisk used for multiplication. However, in this
statement the asterisk is being used to designate a variable as a pointer.
8c. Explain the difference between a null pointer and a void pointer
9a. Discuss the general syntax of structure variable declaration of structure to store book information.
A Structure variable declaration is similar to the declaration of variables of any other data types.
It includes the following elements.
• Keyword struct: The keyword struct is used at the beginning while defining a
structure in C. Similar to a union, a structure also starts with a keyword.
• structName: This is the name of the structure which is specified after the keyword
struct.
• data_Type: The data type indicates the type of the data members of the
structure. A structure can have data members of different data types.
• member_name: This is the name of the data member of the structure. Any number
of data members can be defined inside a structure. Each data member is allocated a
separate space in the memory.
9c. Write a program to write employees details in a file called employee.txt. Then read the record of
the nth employee and calculate his salary.
#include<stdio.h>
typedef struct
{
char name[30];
int id;
int salary;
}employee;
int main()
{
int n,i,j;
FILE *fptr;
employee e[10], temp;
/* Reading file in binary read mode */
fptr = fopen("employee.txt","rb");
if(fptr == NULL)
{
printf("File error!");
exit(1);
}
printf("Enter how many records:\n");
scanf("%d",&n);
gets() is used to read string from the standard input device until newline character not found,
use of gets() may risky because it does not check the array bound.
For example: if you have a character array with 20 characters and input is more than 20
characters, gets() will read all characters and store them into variable. Since, gets() does not
check the maximum limit of input characters, so any time compiler may return buffer overflow
error.
fgets()
fgets() is used to read string till newline character or maximum limit of the character array, use
of fgets() is safe as it checks the array bound.
fgets() has following parameters: buffer, maximum length, and input device reference.
10c.Implement structures to read, write and compute average- marks of the students, list the students
scoring above and below the average marks for a class of N students