0% found this document useful (0 votes)
96 views14 pages

Important Instructions To Examiners:: Define The Terms: I) Flow Chart Ii) Algorithm

The document contains model answers and guidelines for examiners for a programming in C exam. It includes answers to questions on topics like flowcharts, algorithms, data types, structures, functions, pointers and arrays. Detailed explanations and examples are provided for various questions.

Uploaded by

sumitbhadane22
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)
96 views14 pages

Important Instructions To Examiners:: Define The Terms: I) Flow Chart Ii) Algorithm

The document contains model answers and guidelines for examiners for a programming in C exam. It includes answers to questions on topics like flowcharts, algorithms, data types, structures, functions, pointers and arrays. Detailed explanations and examples are provided for various questions.

Uploaded by

sumitbhadane22
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/ 14

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

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) Define the terms: 2M
i) Flow chart Each
ii) Algorithm definition 1M
Ans. i) Flow chart: Flow chart is a diagrammatic or pictorial
representation of logic of the program.
ii) Algorithm: Algorithm is a stepwise procedure for solving any
problem in computer.
b) State any four data types used in „C‟ 2M
Ans. Four basic data types in „C‟ are ½M for each
char, int, float and double. data type
c) List logical operators in „C‟ 2M
Ans. Logical Operators in C are: For all
1) OR (||)2) AND (&&)3) NOT (!) logical
operators 2M

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

d) Define structure. Give one example of structure declaration. 2M


Ans. Definition of Structure:
Structure is a collection of variables of similar or different data types Definition
1M
which is represented by a single name. Example 1M
Example:
struct bill
{
int consumer_id;
char address[50];
float amount;
};
e) State any two advantages of function. 2M
Ans. 1) Big code can be difficult to read, so when divided into smaller Any two
functions, it increases readability. advantages
1M each
2) Program becomes modular.
3) It reduces complexity in debugging.
4) It enhances reusability of the code.
f) Write the meaning of „&‟ and * with respect to pointer. 2M
Ans. ‟&‟ is a unary operator in C which returns the memory address of the Meaning of
variable. This is also known as address of operator. ‘&’ 1M,

Meaning of
„*‟ is a unary operator which returns the value pointed by a pointer ‘*’ 1M
variable.
g) Draw any two symbols used to construct flowchart. Also state 2M
their use. Any two
Ans. correct
symbols and
use : 1M
each

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

2. Attempt any THREE of the following: 12


a) Explain any four guidelines for preparation of flow chart. 4M
Ans. 1. The flowchart should be neat, clear and easy to follow. Any 4 guide-
2. Symbols should be used correctly to show flow of program. lines, 1M
each
3. There should not be any ambiguity in understanding the
flowchart.
4. The flowchart is to be read from left to right and top to bottom.
b) Differentiate between while loop and do while loop. 4M
Ans. while do-while Any four
Condition is checked first then Statements are executed at least relevant
points 1M
statements are executed. once, thereafter condition is each
checked.
It is executed zero times, if At least once the statements are
condition is false. executed.
No semicolon at the end of
while. Semicolon at the end of while.
If there is a single statement,
brackets are not required. Brackets are always required.
while loop is entry controlled do-while loop is exit controlled
loop. loop.

c) Explain declaration and initialization of one dimensional array 4M


using example.
Ans. Declaration: Declaration
One dimensional array: 2M
Initialization
An array is a collection of similar type of data which can share a 2M
common name.
Declaration of one dimensional array:
Syntax:-
data type arrayname [size];
Eg :int arr[5];
This will declare array “arr” which can store 5 integers inside it.
Initialization:
Initialization can be done as design time or runtime.
1. Design time: This can be done by providing number of elements of
the declared data type to an array at design time.
Eg :int arr[5]={1,2,3,4,5};

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

2. Runtime: For this loop structures like „for‟ can be used to iterate
through the locations of the array. Here the index of the array starts
with 0 and ends with position one less than the total size of an array.
Eg :
int arr[5];
for(i=0;i<5;i++)
{
scanf(“%d”,&arr[i]);
}

d) Write output for the following programming code: 4M


#include<stdio.h>
#include<conio.h> Correct
output with
void main() x, y values :
{ 2M
int x,y,a, b,*P1, *P2; a,b values :
x = 10; 2M
y = 20;
P1 = &x;
P2 = &y;
a = *P1 * * P2 +20;
b = *P1 * *P2 – 20;
print f(“x=%d, y = %d”, x,y);
print f(“a=%d, b = %d”, a,b);
}
Ans. Output: x=10, y=20a=220, b=180
3. Attempt any THREE of the following: 12
a) Explain data type conversion with example. 4M
Ans. Type conversion: It is referred as Type Casting. It is used to convert Explanation
one data type into another data type. 3M
Example 1M

Implicit conversion : It converts any intermediate values to the


proper type automatically.
Example: If one of the operands is double, the other will converted to
double and the result will be in double data type.

Explicit conversion: The process of converting one data type to


another data type forcefully is known as explicit conversion.
Syntax : (data_type name) expression;

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

Example: double x = 1.2;


int sum = (int)x + 1;
The above statement converts value of variable x from double to
integer.
b) Explain any two string handling functions with syntax and 4M
example.
Ans. 1. strlen function: Any two
strlen( ) function in C gives the length of the given string. strlen( ) function with
Correct
function counts the number of characters in a given string and returns syntax and
the integer value.It stops counting the character when null character is example 2M
found. Because, null character indicates the end of the string in C. each
Syntax:
strlen(stringname);
Example:
Consider str1=”abc”
strlen(str1); returns length of str1 as 3
2. strcat() function:
In C programming, strcat() concatenates (joins) two strings. It
concatenates source string at the end of destination string.
Syntax:
strcat( destination string, source string);
Example:
Consider str1=”abc” and str2=”def”
strcat(str1,str2); returns abcdef in str1 and str2 remains unchanged.
3. strcpy() function
strcpy( ) function copies portion of contents of one string into another
string.
Syntax:
strcpy( destination string, source string);
Example:
Consider str1=”abc”
strcpy(str1,str2); returns abcstr
4.strcmp() function
The strcmp function compares two strings which are passed as
arguments to it. If the strings are equal then function returns value 0
and if they are not equal the function returns some numeric value.
Syntax:
strcmp( str1, str2);

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

Example:
Consider str1=”abc” and str2=”abc”
Then strcmp(str1,str2) returns 0 as both the strings are same.
c) Describe scanf() function with its syntax and example. 4M
Ans. scanf() function: It is used to accept input from user during execution Description
of a program. 2M

Syntax 1M
Syntax: scanf("Control string",arg1,arg2,...,argn); Example 1M
control string specifies the field format in which the data is to be
entered. Control string contains conversion character % and a data
type character and optional number specifying the field width. The
arguments arg1,arg2,...,argn specify the address of locations where
the data is stored. Control string and arguments are separated with
comma. It can also have blanks, tabs, or newlines.

Example: scanf("%d%f",&a, &b);


In the above example, %d inside control string indicates integer data
type whereas %f inside control string indicates float data type.
Ampersand symbol (&) written before variable name is used to
retrieve address / memory location of variable. This scanf ( ) function
accepts one integer value and stores it in variable a and one float
value that is stored in variable b.
d) Describe how recursive function is used in calculating factorial of 4M
a number. Relevant
Ans. Recursive function : description
4M
Recursion is a process of calling a function by itself. a recursive
function body contains a function call statement that calls itself
repetitively.

Example: for calculating factorial of a number using recursion


function call from main() : fact(n); // consider n=5
Function definition:
int fact(int n)
{
if(n==1)
return 1;
else
return(n*fact(n-1));
}

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

In the above recursive function a function call fact (n-1) makes a


recursive call to fact function. Each time when a function makes a
call to itself, it save its current status in stack and then executes next
function call. When fact ( ) function is called from main function, it
initializes n with 5. Return statement inside function body executes a
recursive function call. In this call, first value of n is stored using
push ( ) operation in stack (n=5) and a function is called again with
value 4(n-1). In each call, value of n is push into the stack and then it
is reduce by 1 to send it as argument to recursive call. When a
function is called with n=1, recursive process stops. At the end all
values from stack are retrieved one by one using pop ( ) operation to
perform multiplication to calculate factorial of number.
4. Attempt any THREE of the following: 12
a) Write an algorithm and draw a flowchart to find largest number 4M
from three numbers. Algorithm
Ans. Algorithm: 2M
Step 1:Start Flowchart
Step 2:Declare variables no1,no2,no3 2M
Step 3: Accept / Initialize values for variables no1,no2,no3
Step 4: If no1 >no2 and no1>no3 then
display "no1 is largest"
otherwise check if no2>no1 and no2>no3 then
display "no2 is largest"
otherwise
display "no3 is largest"
Step 5: Stop

Flowchart

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

b) Write a program to convert temperature in Fahrenheit degrees to 4M


Centigrade degrees.
Ans. #include<stdio.h> Input
#include<conio.h> temperature
1M
void main()
{ Conversion
float celsius, fahrenheit; 2M
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &fahrenheit); Display in
Centigrade
celsius = (fahrenheit - 32) * 5 / 9; 1M
printf("Temperature in Fahrenheit =%f Temperature in Centigrade
=%f", fahrenheit, celsius);
getch();
}
c) Write a C program to print following pattern using loop. 4M
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

Ans. #include<stdio.h>
#include<conio.h> Correct logic
2M
void main()
{ Correct
int i,j,n; syntax
clrscr(); 2M
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
getch();
}
d) Write a program to declare an array of 5 elements and display 4M
sum of all array elements. Correct logic
Ans. Accepting input from user 2M
#include<stdio.h> Correct
#include<conio.h> syntax 2M
void main()
{
int a[5],i,sum=0;
clrscr();
printf("Enter array elements:");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
for(i=0;i<5;i++)
sum=sum+a[i];
printf("\n Sum= %d",sum);
getch();
}

OR
#include<stdio.h>
#include<conio.h>
void main()
{

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

int a[5]={1,2,3,4,5},i,sum=0; // Array initialization at the time of


declaration
clrscr();
for(i=0;i<5;i++)
sum=sum+a[i];
printf("\n Sum= %d",sum);
getch();
}
e) Write a C program using function to find area of circle. 4M
Ans. Note: Any type of function declaration and definition shall be
considered (with return value or no return value or with Main
function 2M
parameter or no parameter)
#include<stdio.h> Function to
#include<conio.h> calculate
void area(float radius) area 2M
{
float a;
a=3.14*radius*radius;
printf("Area of circle= %f",a);
}
void main()
{
float r;
printf("Enter the radius of circle : ");
scanf("%f", &r);
area(r);
getch();
}
5. Attempt any TWO of the following: 12
a) Write a C program with comments to reverse the digit of integer 6M
number. For example the number 12345 should be displayed as
54321.
Ans. #include<stdio.h>
#include<conio.h> Correct
void main() Input 2M,
{ Correct
int num, res=0,ans=0; Reverse
clrscr(); Function:
printf("Enter the number"); 2M,

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

scanf("%d", &num);
while(num!=0) Correct
Output: 2M
{
res=num%10;
ans=ans*10+res;
num=num/10;
}
printf("Reverse number is %d", ans);
getch();
}

b) Write a program to add two 3 x 3 matrices. Display the addition. 6M


Ans. #include<stdio.h> Declaration
#include<conio.h> of variables
1M,
void main()
{ Input
int a[3][3],b[3][3],c[3][3],i,j; matrices 2M,
clrscr();
printf("Enter first matrix elements:\n"); Calculating
addition 2M,
for(i=0;i<3;i++)
{ Display
for(j=0;j<3;j++) addition 1M
{
scanf("%d",&a[i][j]);
}
}
printf("\nEnter second matrix elements:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
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];

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

}
}
printf("\n\nAddition of two matrices is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d ",c[i][j]);
}
printf("\n");
}
getch();
}

c) Write a program to find largest number from an array using 6M


pointer.
Ans. #include<stdio.h> Accepting
#include<conio.h> array
elements 2M,
void main()
{ finding
int n,*ptr,i,largest=0; largest
clrscr(); element
printf("Enter how many numbers u want::"); using pointer
3M,
scanf("%d",&n);
for(i=0;i<n;i++) Display of
{ largest
printf("\nEnter Number %d :: ",i+1); element 1M
scanf("%d",(ptr+i));
}
largest=*ptr;
for(i=1;i<n;i++)
{
if(*(ptr+i)>largest)
largest=*(ptr+i);
}
printf("\nThe Largest Number is %d \n",largest);
getch();
}

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

6. Attempt any TWO of the following: 12


a) Write a C program to declare structure employee having data 6M
member name, age, designation and salary. Accept and display
information of 1 employee. Declaration
Ans. #include<stdio.h> of structure-
2M,
#include<conio.h>
struct employee Accepting
{ data- 2M,
char name[20],designation[10];
int age; Displaying
data -2M
long salary;
};
void main()
{
int i;
struct employee e;
clrscr();
printf("\n Enter name:");
scanf("%s",&e.name);
printf("\n Enter age:");
scanf("%d",&e.age);
printf("\n Enter designation:");
scanf("%s",&e.designation);
printf("\n Enter salary:");
scanf("%ld",&e.salary);
printf("\n\nEmployee's data is:");
printf("\n Name=%s",e.name);
printf("\n Age=%d",e.age);
printf("\n Designation=%s",e.designation);
printf("\n Salary=%ld",e.salary);
getch();
}
b) Write a program to find factorial of a number using recursion 6M
Ans. #include<stdio.h>
#include<conio.h> Recursive
function 4M,
int factorial(int no)
{
if(no==1)
return(1);

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

WINTER – 2022 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

else
return(no*factorial(no-1)); Main
function 2M
}
void main()
{
int fact,no;
clrscr();
printf("\n Enter number: ");
scanf("%d",&no);
fact=factorial(no);
printf("\n Factorial number=%d",fact);
getch();
}
c) Write a C program using pointer to read an array of characters 6M
and print them in reverse order.
Accepting
#include<stdio.h> string 1M,
Ans. #include<conio.h> Pointer
void main() initialization
{ 1M,
char str[10],*ptr;
Logic of
int l=0; reverse using
clrscr(); pointer 3M,
printf("Enter string:");
scanf("%s",str); Displaying
ptr=str; reverse string
1M
while(*ptr!='\0')
{
l=l+1;
ptr=ptr+1;
}
while(l>0)
{
ptr=ptr-1;
printf("%c",*ptr);
l=l-1;
}
getch();
}

Page 14 / 14

You might also like