0% found this document useful (0 votes)
76 views17 pages

CPR W22

1. The document provides instructions to examiners for evaluating answers to a Basic C Language exam administered by the Maharashtra State Board of Technical Education. 2. It instructs examiners to assess understanding rather than word-for-word matching, and to give partial credit when possible. It also provides flexibility for answers and figures in different but equivalent forms. 3. The document provides a sample exam question and answer key to illustrate the expectations and grading approach for the C Language exam.

Uploaded by

Mugdha Tamhan
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)
76 views17 pages

CPR W22

1. The document provides instructions to examiners for evaluating answers to a Basic C Language exam administered by the Maharashtra State Board of Technical Education. 2. It instructs examiners to assess understanding rather than word-for-word matching, and to give partial credit when possible. It also provides flexibility for answers and figures in different but equivalent forms. 3. The document provides a sample exam question and answer key to illustrate the expectations and grading approach for the C Language exam.

Uploaded by

Mugdha Tamhan
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/ 17

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218
Important Instructions to examiners:
1) The answers should be examined by key words and not as word-to-word as given in the
model answer scheme.
2) The model answer and the answer written by candidate may vary but the examiner may
try to assess the understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more
Importance (Not applicable for subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in
the figure. The figures drawn by candidate and model answer may vary. The examiner
may give credit for anyequivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed
constant values may vary and there may be some difference in the candidate’s answers
and model answer.
6) In case of some questions credit may be given by judgement on part of examiner of
relevant answer based on candidate’s understanding.
7) For programming language papers, credit may be given to any other program based on
equivalent concept.
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi
and Bilingual (English + Marathi) medium is introduced at first year of AICTE diploma
Programme from academic year 2021-2022. Hence if the students in first year (first and
second semesters) write answers in Marathi or bilingual language (English +Marathi), the
Examiner shall consider the same and assess the answer based on matching of concepts
with model answer.

Q. Sub Answer Marking


No Q.N. Scheme
1. Attempt any FIVE of the following: 10
a) List any four relational operators 2M
Ans. Operator Meaning Any four
< Is less than operators
½ M each
<= Is less than equal to
> Is greater than
>= Is greater than equal to
== Is equal to
!= Is not equal to
b) Give the syntax of switch case statement. 2M
Ans. Syntax: Correct
switch (variable / expression) syntax 2M
{
case value1:

Page 1 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218
statements;
break;
case value2:
statements;
break;
.
.
.
default:
statements;
}

c) State the use of break and continue statement 2M


Ans. break statement: It is used to exit from loop/block. When break Correct use
statement is executed inside any loop or with switch case or block, of break
1M
control automatically passes to the first statement outside the loop / continue
block. 1M

continue statement: It is used to skip execution of remaining


statements in an iteration and pass control at the beginning of loop.

d) Define the term function 2M


Ans. Function is a collection / set of statements / instructions written to Correct
perform a specific task. definition
2M

e) State any two advantages of pointers. 2M


Ans. Advantages of pointers: - Any two
1. Reduces the storage space and complexity of the program. correct
advantages
2. Reduces the execution time of the program. 2M
3. Provides an alternate way to access array elements.
4. Pointers allow us to resize the dynamically allocated memory
block.
5. Addresses of objects can be extracted using pointers.
6. Increase access speed.
7. Pointers permit references to functions and thereby facilitate
passing of functions as arguments to other functions.

f) State the use of ‘&’ and ‘*’ operators used in / with pointer 2M

Page 2 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218

Ans. &Operator: -It is used to return the memory address of the variable. It
is also known as address of operator. Use of ‘&’
1M
OR
It is used to retrieve address of a variable from memory. Use of ‘*’
*Operator: - It is used to declare a pointer variable. Also used to 1M
access the value of a variable whose address is stored in a pointer
variable.
Example: int *ptr,a;
ptr=&a;

g) Write any two features of structure. 2M


Ans.  Structure is a user defined data type Any two
correct
 Structure allows grouping of two or more similar or different data features
types or data structures together into a single type. 1M each
 Structure reduces complexity of a program code by using one
group instead of using different arrays for different variables.
 Structure helps to construct a complex data type which is more
meaningful.
 Structure can be passed to the function either by value or by
reference.
2. Attempt any THREE of the following: 12
a) State the use of %d and %f. Also write example with printf 4M
statement to show use of mentioned format specifiers.
Ans. Format specifier tells the compiler what type of data a variable holds correct use
of %d 1M,
during taking input and printing output using scanf() and printf()
functions respectively.
%f 1M,
%d - It is used to tell the compiler that variable holds integer type
value.
example-
%f - It is used to tell the compiler that variable holds float type value. 2M

Example:-
int a;
float b;
a=2;
b=2.5;
printf(“%d%f”,a,b);

Page 3 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218

b) Compare while and do-while loop 4M


Ans. While Do while Any four
In 'while' loop the controlling In 'do-while' loop the correct
points 1M
condition is at the start of the controlling condition is at the each
loop. end of the loop.
If the condition is evaluating to Even if the condition is false
true then only statements inside loop statements executes at least
the loop executes. once.
It is an entry controlled loop It is an exit controlled loop
Syntax : Syntax:
while(condition) do
{ {
Code; Code;
} } while(condition);
c) Define the term array. Give syntax to declare an array. Also write 4M
two advantages of array.
Ans. An array is a collection of similar type of elements.
Definition
1M
Syntax: data_type array_variable_name[size]; Syntax 1M

Advantages of array:
1. It is better and convenient way of storing the data of same datatype
with same size.
2. It allows to store multiple elements in it.
3. Accessing an element is very easy by using index number.
4. An array allows storing and access of a large number of values by Any two
writing a small piece of code instead of declaring each variable advantages
2M
separately.
5. Arrays store elements in a sequential manner in memory locations,
so no extra memory is allocated thus preventing the wastage of
memory.
6. Iterating the arrays using their index is faster.
7. It allows to store the elements in any dimensional array – supports
multidimensional array.
8. Arrays are one of the most basic data structures and are used for
processing many algorithms like searching and sorting, maximum
and minimum values, reversing, etc. in simple and easy ways

Page 4 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218

d) Differentiate between call by value and call by reference method 4M


for passing parameters. Any four
Ans. Call by value Call by reference points 1M
each
A function is called by A function is called by passing
passing value of a variable in address of variable in a
a function call. function call.
A copy of actual parameter is No copy is created for actual
created when function parameters.
executes.
Address of actual and formal Address of actual and formal
parameters are different. parameters are same.
Changes made inside the Changes made inside the
function does not affect function affects actual
actual parameters. parameters.
Example: Example:
Function definition: Function definition:
void swap(int x,int y) void swap(int *x,int *y)
{ {
} }
Function call: Function call:
swap(x,y); swap(&x,&y);

3. Attempt any THREE of the following: 12


a) Describe with suitable example difference between pre-increment 4M
and post-increment operators.
Ans. Pre-increment (++a)
Before assigning the value to the variable, the value is incremented Explanatio
n of pre-
by one. increment
Example: with
example
#include < stdio.h >
2M
int main()
{
int a = 10, b;
b = ++a;
printf("b = %d\n\n", b);
printf("a = %d\n", a);
return 0;

Page 5 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218

}
Here first the value of a increments and then is assigned to variable b.
So both a and b value will be 11.

Post-increment (a++) Explanatio


After assigning the value to the variable, the value is incremented. n of post
Example: increment
with
#include < stdio.h > example
int main() 2M
{
int a = 10, b;
b = a++;
printf("b = %d\n\n", b);
printf("a = %d\n", a);
return 0;
}
Here first value of a(i.e., 10) is assigned to b and then value of a is
incremented. So
b = 10 and a = 11 is printed.

b) Describe declaration and initialization of two dimensional array 4M


with suitable example.
Ans. The array which is used to represent and store data in a tabular form
Declaratio
is called as two-dimensional array. Such type of array is specially n of 2D
used to represent data in a matrix form. array 1M,
Declaration of two-dimensional array:
Syntax:-
data type arrayname [row size] [column size]; Initializati
on of 2D
Eg: array 1M,
int arr[3][4];
This will declare an array „arr‟ with 3 rows and 4 columns.
Initialization of two-dimensional array:
Syntax: Example
2M
data_type arraname[rowsize][columnsize]={array elements};
E.g.
int arr[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};
This will initialize an array „arr‟ with 12 array elements.

Page 6 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218

Example:
main()
{
int a[2][2]={{1,2},{4,5});
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf(“%d”,a[i][j]);
}
printf(“\n”);
}
c) Describe pointer arithmetic with any two operations 4M
Ans. The pointer arithmetic is done as per the data type of the pointer. The
basic operations on pointers are:
Increment: Any two
It is used to increment the pointer. Each time a pointer is operation
incremented, it points to the next location with respect to memory
size. Descriptio
Example: n
with
If ptr is an integer pointer stored at address 1000, then ptr++ shows example
1002 as incremented location for an int. It increments by two each 2M
locations as it requires two bytes storage.

Decrement:
It is used to decrement the pointer. Each time a pointer is
decremented, it points to the previous location with respect to
memory size.
Example:
If the current position of pointer is 1002, then decrement operation
ptr-- results in the pointer pointing to the location 1000 in case of
integer pointer as it require two bytes storage.

Addition
When addition operation is performed on pointer, it gives the location
incremented by the added value according to data type.

Page 7 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218

Example:
If ptr is an integer pointer stored at address 1000, Then ptr+2 shows
1000+(2*2) = 1004 as incremented location for an int.

Subtraction
When subtraction operation is performed on the pointer variable, it
gives the location decremented by the subtracted value according to
data type.
Example:
If ptr is an integer pointer stored at address 1004, Then ptr-2 shows
1004-(2*2) = 1000 as decremented location for an int.
d) Describe the use of Enumerated data type with example. 4M
Ans. Enumerated data type Correct
1. The Enumerated data type allows the programmer to invent the explanatio
n 2M
programmer's own data type and decide what value the variables of
this data type may carry. Example
2. Enum or enumerator is an integer or number with defined meaningful 2M
names.
3. Enum is often used inside C programs to replace a hard-coded
number with some meaningful symbols.
Example:
include <stdio.h>
enumdays{Sunday=1, Monday, Tuesday, Wednesday, Thursday,
Friday, Saturday};
int main()
{
for(int i=Sunday;i<=Saturday;i++){
printf("%d, ",i);
}
return 0;
}
4. Attempt any THREE of the following: 12
a) Write an algorithm and draw flowchart to find whether number 4M
entered is even or odd Algorithm
Ans. Algorithm: 2M
Step 1- Start
Step 2- Read / input the number.
Step 3- if n%2==0 then number is even.
Step 4- else number is odd.

Page 8 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218
Step 5- display the output.
Step 6- Stop

Flowchart: Correct
flowchart
with
notations
2M

b) Write a C program to check the number entered is positive or 4M


negative and display message accordingly.
Ans. #include <stdio.h> Correct
void main() logic 2M
{ Correct
int num; syntax 2M
printf("Input a number :");
scanf("%d", &num);
if (num >= 0)
printf("%d is a positive number \n", num);
else
printf("%d is a negative number \n", num);
}

c) Write a C program to add two 3 x 3 matrices 4M


Ans. #include<stdio.h>
#include<conio.h>
Declaratio
void main() n of
{ variables
int a[3][3],b[3][3],c[3][3],i,j; 1M,
clrscr();

Page 9 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218
printf("\n Enter first matrix");
for(i=0;i<3;i++)
Input
{ matrices
for(j<0;j<3;j++) 1M,
{
scanf(“%d”,&a[i][j]);
} calculating
addition
} 1M,
printf("\n Enter second matrix");
for(i=0;i<3;i++)
{ Display
for(j=0;j<3;j++) addition
1M
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("\n Addition:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}

d) Write a C program using pointer to swap the value of two integer 4M


numbers.

Page 10 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218

Ans. #include<iostream.h>
#include<conio.h> Correct
void swap(int *a, int *b) logic 2M
{ Correct
int temp; syntax 2M
temp=*a;
*a=*b;
*b=temp;

}
void main()
{
int a,b;
clrscr();
cout<<"\nEnter the value of a:";
cin>>a;
cout<<"\nEnter the value of b:";
cin>>b;
cout<<"\nBefore swapping:";
cout<<"\na="<<a;
cout<<"\nb="<<b;
swap(&a,&b);
cout<<"\n\nAfter swapping:";
cout<<"\na="<<a;
cout<<"\nb="<<b;
getch();
}
OR
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, *p;
clrscr();
printf("Enter value of a: ");
scanf("%d",&a);
printf("Enter value of b: ");
scanf("%d",&b);
printf("Before swapping: a:%d b:%d",a,b);

Page 11 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218
*p = a;
a = b;
b = *p;
printf("\nAfter swapping: a:%d b:%d",a,b);
getch();
}

e) Describe with suitable example initialization and accessing 4M


structure members using pointer.
Ans. Declare a Structure Pointer
Syntax: Initializati
struct structure_name *ptr; on 1M,

Accessing
Initialization of the Structure Pointer structure
Syntax: member
using
ptr = &structure_variable; pointer
1M,
Access Structure member using pointer:
There are two ways to access the member of the structure using
Structure pointer:
1. Using ( * ) asterisk or indirection operator and dot ( . ) operator.
2. Using arrow ( -> ) operator or membership operator.

#include <stdio.h>
struct Subject
{ Example
// declare the member of the Course structure 2M
char sub_name[30];
int sub_id;
char sub_duration[50];
char sub_type[50];
};
int main()
{
struct Subject sub;
struct Subject *ptr;
ptr =&sub;
strcpy (sub.sub_name, " Computer Science");

Page 12 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218
sub.sub_id = 1201;
strcpy (sub.sub_duration, "6 Months");
strcpy (sub.sub_type, " Multiple Choice Question");
printf (" Subject Name: %s\t ", (*ptr).sub_name);
printf (" \n Subject Id: %d\t ", (*ptr).sub_id);
printf (" \n Duration of the Subject: %s\t ", (*ptr).sub_duration);
printf (" \n Type of the Subject: %s\t ", (*ptr).sub_type);
return 0;
}
5. Attempt any TWO of the following: 12
a) Describe the use of nested if-else statement with syntax and 6M
example.
Ans. (Any program using if else statement shall be considered.)
Use 2M
When a series of decision is required, nested if-else is used. Nesting
means using one if-else construct within another one.
Syntax:
If(condition1)
{
Code of action if condition1 is true;
If (condition2) Syntax 2M
{
Code of action if condition2 is true;
}
else
{
Code of action if condition2 is false;
}
}
else
{
Code of action if condition1 is false;
}
Example :
Example
If(subject1 >=40) 2M
{
printf(“Pass in subject1”);
if(subject2>=40)
{
printf(“Pass in both subjects”);

Page 13 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218
}
else
{
printf(“Failed in subject 2”);
}
}
else
{
printf(“Failed in subject 1”);
}
b) Write a C program to read string from keyboard and find 6M
whether it is palindrome or not. Correct
Ans. #include <stdio.h> logic 3M
#include <string.h>
main()
{
char str[25]; Correct
int flag=0,i; syntax 3M
printf("Enter a string :");
scanf("%s",str);
int l = strlen(str) - 1;
for(i=0;i<l;i++)
{
if (str[i++] != str[l--])
{
printf("%s is not a palindrome\n", str);
flag=1;
break;
}
}
if(flag==0)
printf("%s is a palindrome\n", str);
}
OR
#include <stdio.h>
#include <string.h>
main()
{
char str1[25];

Page 14 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218
printf("Enter a string :");
scanf("%s",str1);

if(strcmp(str1,strrev(str1))==0)
printf("%s is a palindrome\n", str);
else
printf("%s is a not a palindrome\n", str);
}
c) Write a C program to display Fibonacci series using recursion. 6M
Ans. #include<stdio.h> Correct
main() logic 3M
{ Correct
int n, m= 0, i; syntax 3M
printf("Enter Total terms:");
scanf("%d", &n);
printf("Fibonacci series terms are:");
for(i = 1; i<= n; i++)
{
printf("%d ", fibonacci(m));
m++;
}
}
int fibonacci(int n)
{
if(n == 0 || n == 1)
return n;
else
return(fibonacci(n-1) + fibonacci(n-2));
}

6. Attempt any TWO of the following: 12


a) Write a C program to accept two strings from user. Display 6M
length of both the strings. Also Concatenate two strings and
display the output.
Ans. #include <stdio.h>
#include <string.h>
main()
{ Correct
char str1[20]; logic 3M

Page 15 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218
char str2[20]; Correct
int l1,l2; syntax 3M
printf("Enter first string :");
scanf("%s",str1);
printf("Enter second string :");
scanf("%s",str2);
l1=strlen(str1);
l2=strlen(str2);
strcat(str1,str2);
printf("Length of first String %s : %d\n",str1,l1);
printf("Length of second String %s : %d\n",str2,l2);
printf("Concatenated String: %s\n", str1);
}

b) Write a C program to accept two numbers. Write a function 6M


add() to display addition of entered numbers and function mult()
to display multiplication of entered numbers.
Ans. #include <stdio.h>
#include <string.h> Correct
int add(int,int); logic 3M
int mult(int,int); Correct
main() syntax 3M
{
int n1,n2, result1,result2;
printf("Enter first number :");
scanf("%d",&n1);
printf("Enter second number :");
scanf("%d",&n2);
result1=add(n1,n2);
result2=mult(n1,n2);
printf("Addition : %d\n ",result1);
printf("Multiplication : %d\n ",result2);
}
int add(inta,int b)
{
int c;
c=a+b;
return(c);
}

Page 16 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Basic C Language Subject Code: 22218
int mult(int a , int b)
{
int c;
c=a*b;
return(c);
}
c) Write a C program to declare structure ‘employee’ having data 6M
members as empid, empname and empaddress. Accept this data
for 5 employees and display it.
Ans. #include <stdio.h> Correct
struct Employee logic 3M
{ Correct
char Empname[50]; syntax 3M
int Empid;
char Empaddress[50];
} emp[5];
main()
{
int i;
for(i=0;i<5;i++)
{
printf("Enter empid,empname and address for employee %d:",i+1);
scanf("%d",&emp[i].Empid);
scanf("%s",emp[i].Empname);
scanf("%s",emp[i].Empaddress);
}
for(i=0;i<5;i++)
{
printf("\n---------------------\n");
printf("Emp id: %d\n", emp[i].Empid);
printf("Emp Name: %s\n", emp[i].Empname);
printf("Address: %s\n", emp[i].Empaddress);
}
printf("\n---------------------\n");
}

Page 17 / 17

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy