0% found this document useful (0 votes)
14 views146 pages

PIC (All Papers)

The document is an examination paper for a 'C' programming course, consisting of multiple sections with various questions that test knowledge on arrays, pointers, functions, and control structures. It includes instructions for answering questions, as well as a model answer section that provides guidance on how to evaluate student responses. The paper emphasizes the importance of understanding programming concepts and the ability to write and explain code.

Uploaded by

randad nikita
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)
14 views146 pages

PIC (All Papers)

The document is an examination paper for a 'C' programming course, consisting of multiple sections with various questions that test knowledge on arrays, pointers, functions, and control structures. It includes instructions for answering questions, as well as a model answer section that provides guidance on how to evaluate student responses. The paper emphasizes the importance of understanding programming concepts and the ability to write and explain code.

Uploaded by

randad nikita
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/ 146

21718

22226
3 Hours / 70 Marks Seat No.

Instructions : (1) All Questions are compulsory.


(2) Answer each next main Question on a new page.
(3) Illustrate your answers with neat sketches wherever necessary.
(4) Figures to the right indicate full marks.
(5) Assume suitable data, if necessary.
(6) Mobile Phone, Pager and any other Electronic Communication
devices are not permissible in Examination Hall.
(7) Preferably, write the answers in sequential order.

Marks

1. Attempt any FIVE of the following : 10

(a) Define :

(i) Two dimensional array

(ii) Multi-dimensional array

(b) Give any four advantages of pointer.

(c) Define type casting. Give any one example.

(d) State any four decision making statements.

(e) State any four math functions with its use.

(f) State the use of following symbols used for flowchart drawing :

(i) (ii)

(iii) (iv)

(g) State use of while loop with syntax.


[1 of 4] P.T.O.
22226 [2 of 4]
2. Attempt any THREE of the following : 12

(a) Develop a simple ‘C’ program for addition and multiplication of two integer

numbers.

(b) Explain how to pass pointer to function with example.

(c) Explain following functions :

getchar( )

putchar( )

getch( )

putch( )

with suitable examples.

(d) Develop a program to accept an integer number and print whether it is

palindrome or not.

3. Attempt any THREE of the following : 12

(a) State the use of printf( ) & scanf( ) with suitable example.

(b) Explain any four library functions under conio.h header file.

(c) Explain how formatted input can be obtain, give suitable example.

(d) Develop a program to find factorial of a number using recursion.


22226 [3 of 4]
4. Attempt any THREE of the following : 12

(a) Write a program to sweep the values of variables a = 10, b = 5 using function.

(b) Develop a program using structure to print data of three students having data
members name, class, percentage.

(c) Design a program to print a message 10 times.

(d) Draw a flowchart for checking whether given number is prime or not.

(e) Implement a program to demonstrate logical AND operator.

5. Attempt any TWO of the following : 12

(a) Draw a flowchart of Do-while loop and write a program to add numbers until
user enters zero.

(b) Give a method to create, declare and initialize structure also develop a
program to demonstrate nested structure.

(c) Implement a program to demonstrate concept of pointers to function.

6. Attempt any TWO of the following : 12

(a) Develop a program to swap two numbers using pointer and add swaped
numbers also print their addition.

(b) Design a programme in C to read the n numbers of values in an array and


display it in reverse order.

(c) Develop a program to find diameter, circumference and area of circle using
function.

_______________

P.T.O.
22226 [4 of 4]
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

MODEL ANSWER
SUMMER – 2018 EXAMINATION
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 any equivalent 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.

Q. Sub Answer Marking


No Q.N. Scheme
.
1. Attempt any FIVE of the following: 10
(a) Define: 2M
(i) Two dimensional array
(ii) Multi-dimensional array
Ans. (i) Two dimensional array
Two dimensional array is a collection of similar type of data elements Definitio
arranged in the form of rows & columns. n of two-
E.g. Array can be declared as int arr[3][3]; dimensi
In this there can be 9 elements in an array with 3 rows and 3 columns. onal
array
(ii) Multi-dimensional array: 1M
An array with more than one dimension is called as multi-
dimensional array.
For example, Multi-
float x[3][4]; dimensi
Similarly, you can declare a three-dimensional (3d) array. For onal
example, array
float y[2][4][3]; 1M

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

Here, The array y can hold 24 elements.


(b) Give any four advantages of pointer. 2M
Ans. Advantages of pointer:
1. Pointers reduce the length and complexity of a program. Any
2. They increase execution speed. four
3. A pointer enables us to access a variable that is defined advanta
outside the function. ges ½M
4. Pointers are more efficient in handling the data tables. each
5. The use of a pointer array of character strings results in
saving of data storage space in memory.
6. It supports dynamic memory management.
(c) Define type casting. Give any one example. 2M
Ans. Definition type casting:
The conversion of one data type to another is known as type casting.
The values are changed for the respective calculation only, not for Definitio
any permanent effect in a program. n of type
casting
For example, 1M
x=int (7.5) means 7.5 is converted to integer by truncating it i.e. 7
b=(int) 22.7/(int) 5.3 means 22.7 will be converted to 22 and 5.3 to 5
so answer will be 22/5=4 Any one
c=(double) total/num means the answer will be in float value. correct
p=sin((int)x) means x will be converted to integer and then sine angle Example
will be calculated. 1M
(d) State any four decision making statement. 2M
Ans. Decision making statement: Any
1. if statement four
2. if-else statement correct
3. if-else-if ladder decision
4. Nested if-else statement making
5. switch statement statemen
6. conditional operator statement (? : operator) ts - ½ M
each
(e) State any four math functions with its use. 2M
(Note: Any other relevant math function shall be considered) Any
Ans. Math Functions: four
sqrt() - square root of an integer correct
abs() - absolute value of an integer math

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

sin() - compute the sine value of an input value function


cos()- compute the cosine value of an input value with its
pow()- compute the power of a input value use ½M
floor()- round down the input value each
ceil()- round up the input value
(f) State the use of following symbols used for flowchart drawing: 2M

Ans. (i) General processing


Correct
(ii) Decision making use of
symbols
½M
(iii) Input/ Output statements each

(iv) Start / Stop

(g) State use of while loop with syntax. 2M


Ans. While loop is used in programming to repeat a specific block of
statement until some end condition is met. Use of
while
The syntax of a while loop is: loop 1M
while (test Expression)
{ Syntax
Statements… of while
statements…. loop 1M
}
2. Attempt any THREE of the following: 12
(a) Develop a simple ‘C’ program for addition and multiplication of 4M
two integer numbers.
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h>
#include<conio.h> Correct
void main() Logic
{ 2M
int a,b,add,mul;

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

clrscr();
printf("Enter value for a and b:"); Correct
scanf("%d%d",&a,&b); syntax
add=a+b; 2M
mul=a*b;
printf("\nAddition of a and b=%d\n",add);
printf("\Multiplication of a and b=%d",mul);
getch();
}
(b) Explain how to pass pointer to function with example. 4M
(Note: Any other example showing pointer as a parameter in
function shall be considered)
Ans. When pointer (addresses) is passed to the function as an argument Explana
instead of value then function is called as call by reference. tion 2M

Example:
#include<stdio.h>
#include<conio.h>
int add(int *);
void main()
{
int *ptr,pos=0;
clrscr();
printf("Enter position:"); Example
scanf("%d",&pos); 2M
ptr=&pos;
printf("\nSum=%d",add(ptr));
getch();
}
int add(int *p)
{
int i=0;
int sum=0;
for(i=1;i<=(*p);i++)
{
sum=sum+i;
}
return sum;
}

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

In the above program function passes the address of „pos‟ to the ptr.
The value of ptr is passed while calling the function. In function
definition in *p it takes value of ptr instead of address for performing
addition of numbers up to specific position.
(c) Explain following functions: 4M
getchar( )
putchar( )
getch( )
putch( )
with suitable examples.
Ans. getchar( ) -
It is function from stdio.h header file. This function is used to input a
single character.
The enter key is pressed which is followed by the character that is
typed. The character that is entered is echoed. Explana
tion of
Syntax: each
ch=getchar(); function
Example: 1M
void main()
{
char ch;
ch = getchar();
printf("Input Char Is :%c",ch);
}
During the program execution, a single character gets or read
through the getchar(). The given value is displayed on the screen
and the compiler waits for another character to be typed. If you
press the enter key/any other characters and then only the given
character is printed through the printf function.

putchar( ) -
It is used from standard input (stdio.h) header file.
This function is the other side of getchar. A single character is
displayed on the screen.
Syntax:
putchar(ch);
void main()
{

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

char ch='a';
putchar(ch);
getch();
}

getch( ) -
It is used from the console (conio.h) header file.
This function is used to input a single character.
The character is read instantly and it does not require an enter key to
be pressed.
The character type is returned but it does not echo on the screen.
Syntax:
ch=getch();
Where, ch - assigned the character that is returned by getch().
void main()
{
char ch;
ch = getch();
printf("Input Char Is :%c",ch);
}
During the program execution, a single character gets or read through
the getch(). The given value is not displayed on the screen and the
compiler does not wait for another character to be typed. And then,
the given character is printed through the printf function.

putch( )-
It is used from console input output header file (conio.h) This
function is a counterpart of getch().
Which means that it will display a single character on the screen.
The character that is displayed is returned.
Syntax:
putch(ch); Where, ch - the character that is to be printed.
void main()
{
char ch='a';
putch(ch)
}
(d) Develop a program to accept an integer number and print 4M
whether it is palindrome or not.

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

(Note: If string is considered instead of number for palindrome


checking, then that logic shall be considered)
Ans. #include<stdio.h>
#include<conio.h>
void main() Correct
{ Logic
int n,num,rev=0,digit,i; 2M
clrscr();
printf("Enter the number: ");
scanf("%d",&num); Correct
n=num; syntax
for(i=0;num!=0;++i) 2M
{
digit=num%10;
rev=rev*10+digit;
num=num/10;
}
if(n==rev)
printf("Number is palindrome");
else
printf("Number is not palindrome");
getch();
}
3. Attempt any THREE of the following: 12
(a) State the use of printf( ) & scanf( ) with suitable example. 4M
Ans. printf( ) & scanf( ):
printf() and scanf() functions are library functions in C programming
language defined in “stdio.h”.
Explana
printf() function is used to print the character, string, float, integer, tion of
octal and hexadecimal values onto the output screen. printf,
scanf
scanf() function is used to read character, string, numeric data from 1M each
keyboard.
%d format specifier is used in printf() and scanf() to specify the value
of an integer variable.
%c is used to specify character,
%f for float variable, %s for string variable, and %x for hexadecimal
variable.

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

Example:
#include<stdio.h>
#include<conio.h>
void main() {
int i; Example
clrscr(); 2M
printf("Enter a number");
scanf("%d",&i);
printf("Entered number is: %d",i);
getch();
}
(b) Explain any four library functions under conio.h header file. 4M
Ans. clrscr() -This function is used to clear the output screen.
getch() -It reads character from keyboard
getche()-It reads character from keyboard and echoes to o/p screen Any 4
putch - Writes a character directly to the console. function
textcolor()-This function is used to change the text color 1M each
textbackground()-This function is used to change text background
(c) Explain how formatted input can be obtain, give suitable 4M
example.
Ans. Formatted input:
When the input data is arranged in a specific format, it is called
formatted input. scanf function is used for this purpose in C.
General syntax: Explana
scanf(“control string”, arg1, arg2..); tion 2M

Control string here refers to the format of the input data. It includes
the conversion character %, a data type character and an optional
number that specifies the field width. It also may contain new line
character or tab. arg1, arg2 refers to the address of memory locations
where the data should be stored.
Example:
scanf(“%d”,&num1);

Eg:
#include<stdio.h> Example
#include<conio.h> 2M
void main()
{

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

int i;
clrscr();
printf("Enter a number");
scanf("%d",&i);
printf("Entered number is: %d",i);
getch();
}
(d) Develop a program to find factorial of a number using recursion. 4M
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h>
#include<conio.h>
int factorial(int num)
{ Correct
if(num==1) syntax
{ 2M
return 1;
}
else
{ Correct
return(num*factorial(num-1)); logic 2M
}
}
void main() {
int num;
int result;
clrscr();
printf("Enter a number");
scanf("%d",&num);
result=factorial(num);
printf("Factorial of %d is %d",num,result);
getch();
}
4. Attempt any THREE of the following: 12
(a) Write a program to sweep the values of variables a = 10, b = 5 4M
using function.
(Note : Read sweep as swap in the question)
(Note: Any other logic using function shall be considered)
Ans. #include<stdio.h>
#include<conio.h>

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

void swapvalues(int *i, int *j)


{
int temp; Correct
temp=*i; syntax
*i=*j; 2M
*j=temp;
}
void main() {
int a=10; Correct
int b=5; logic 2M
clrscr();
printf("The values before swaping:\na=%d, b=%d",a,b);
swapvalues(&a,&b);
printf("\nThe values after swaping:\na=%d, b=%d",a,b);
getch();
}
(b) Develop a program using structure to print data of three students 4M
having data members name, class, percentage.
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h>
#include<conio.h>
void main() {
struct student Correct
{ syntax
char name[20]; 2M
char c[20];
int per;
} s[3];
int i; Correct
clrscr(); logic 2M
for(i=0;i<3;i++)
{
printf("Enter name, class, percentage");
scanf("%s%s%d",&s[i].name,&s[i].c,&s[i].per);
}
for(i=0;i<3;i++)
{
printf("%s %s %d\n",s[i].name,s[i].c,s[i].per);
}

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

getch();
}
(c) Design a program to print a message 10 times. 4M
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h>
#include<conio.h> Correct
void main() syntax
{ 2M
int i;
clrscr(); Correct
for(i=0;i<10;i++) logic 2M
{
printf("Welcome to C programming\n");
}
getch();
}
(d) Draw a flowchart for checking whether given number is prime or 4M
not.
(Note: Any correct flowchart shall be considered)
Ans.

Correct
symbols
1M

Correctn
ess of
flowchar
t 3M

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

(e) Implement a program to demonstrate logical AND operator. 4M


(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h>
#include<conio.h>
void main()
{ Correct
int i; Syntax
int j; 2M
clrscr();
printf("Enter the values of i and j");
scanf("%d%d",&i,&j);
if(i==5 && j==5) { Correct
printf("Both i and j are equal to 5"); logic 2M
} else {
printf("Both the values are different and either or both are not
equal to 5");
}
getch();
}
5. Attempt any TWO of the following: 12
(a) Draw a flowchart of Do-while loop and write a program to add 6M
numbers until user enters zero.
Ans. Flowchart of Do-while loop:

Correct
Flowcha
rt 3M

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

Program:-
#include<stdio.h>
#include<conio.h>
void main()
{ Correct
int no,sum=0; program
clrscr(); 3M
do
{
printf("\n Enter a number:");
scanf("%d",&no);
sum=sum+no;
}while(no!=0);
printf("\n Sum of entered numbers =%d",sum);
getch();
}
(b) Give a method to create, declare and initialize structure also 6M
develop a program to demonstrate nested structure.
Ans. Declaration of structure:-
struct structure_name
{
data_type member 1;
data_type member 2; Creation
. ,
. declarati
. on 2M
data_type member n;
} structure variable 1, structure variable 2,..., structure variable n;

Example:-
struct student
{
int rollno;
char name[10];
}s1;

Initialization:- Initializ
struct student s={1,"abc"}; ation
structure variable contains two members as rollno and name. the 1M

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

above example initializes rollno to 1 and name to "abc".

Program:-
#include<stdio.h>
#include<conio.h>
struct college
{
int collegeid; Program
char collegename[20]; 3M
};
struct student
{
int rollno;
char studentname[10];
struct college c;
};

void main()
{
struct student s={1,"ABC",123,"Polytechnic"};
clrscr();
printf("\n Roll number=%d",s.rollno);
printf("\n Student Name=%s",s.studentname);
printf("\n College id=%d",s.c.collegeid);
printf("\n College name=%s",s.c.collegename);
getch();
}
(c) Implement a program to demonstrate concept of pointers to 6M
function.
(Note: Any other relevant program shall be considered)
Ans. Pointer to function:
include<stdio.h> Correct
int sum(int x, int y) logic 3M
{
return x+y;
} Correct
int main() syntax
{ 3M
int s;

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

int(*fp)(int, int);
fp = sum;
s = fp(10,12);
printf(“Sum = %d”,s);
return 0;
}
6. Attempt any TWO of the following: 12
(a) Develop a program to swap two numbers using pointer and add 6M
swaped numbers also print their addition.
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h>
void swap(int *a,int *b)
{
int temp;
temp=*a; Correct
*a=*b; logic for
*b=temp; swappin
} g using
void main() pointer
{ 4M
int x,y,sum;
printf("\n Enter value for x:");
scanf("%d",&x);
printf("\n Enter value for y:");
scanf("%d",&y); Correct
swap(&x,&y); logic for
printf("\nx=%d",x); addition
printf("\ny=%d",y); &
sum=x+y; display
printf("Sum of x+y = %d",sum); 2M
}
(b) Design a programme in C to read the n numbers of values in an 6M
array and display it in reverse order.
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h> Correct
#include<conio.h> logic for
#define max 50 input
void main() array
{ 3M

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

MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in ‘C’ Subject Code: 22226

int a[max],i,n;
clrscr();
printf("\n Enter number of elements:"); Correct
scanf("%d",&n); logic to
printf("\n Enter array element:"); display
for(i=0;i<n;i++) in
scanf("%d",&a[i]); reverse
printf("\n Array elements in reverse order:"); 3M
for(i=n-1;i>=0;i--)
printf("\t%d",a[i]);
getch();
}
(c) Develop a program to find diameter, circumference and area of 6M
circle using function.
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h>
#include<conio.h>
void circle(float r)
{
float diameter,circumference,area;
diameter=2*r;
printf("\n Diameter=%f",diameter); Correct
circumference=2*3.14*r; logic
printf("\n Circumference=%f",circumference); using
area=3.14*r*r; function
printf("\n Area=%f",area); to find
} diameter
2M,circ
void main() umferen
{ ce 2M,
float radius; area 2M
clrscr();
printf("\n Enter radius:");
scanf("%f",&radius);
circle(radius);
getch();
}

Page 16 / 16
11819
22226
3 Hours / 70 Marks Seat No.

Instructions : (1) All Questions are compulsory.


(2) Illustrate your answers with neat sketches wherever necessary.
(3) Figures to the right indicate full marks.
(4) Assume suitable data, if necessary.
(5) Mobile Phone, Pager and any other Electronic Communication devices
are not permissible in Examination Hall.
(6) Preferably, write the answers in sequential order.

Marks

1. Attempt any FIVE of the following : 10

(a) Define Algorithm.

(b) Give the significance of <math.h> and <stdio.h> header files.

(c) Give syntax of if-else ladder.

(d) Define Array.

(e) Write syntax and use of pow( ) function of <math.h> header file.

(f) Define pointer. Write syntax for pointer declaration.

(g) Draw and label symbols used in flow chart.

[1 of 4] P.T.O.
22226 [2 of 4]
2. Attempt any THREE of the following : 12

(a) Write an algorithm to determine whether a given number is divisible by 5 or


not.

(b) Explain do – while loop with example.

(c) Explain one dimension and two dimension arrays.

(d) Write the output of following c program

#include<stdio.h>

int main ( )

char *ptr;

char str[]=“MAHARASHTRA STATE BOARD OF TECHNICAL


EDUCATION”;

ptr=str;

ptr=ptr+11;

printf(“%s”,++ptr);

return 0;

3. Attempt any THREE of the following : 12

(a) Explain increment and decrement operator.

(b) Explain User defined function with example.

(c) Explain conditional operator with example.

(d) Explain strlen( ) and strcpy( ) function with example.


22226 [3 of 4]
4. Attempt any THREE of the following : 12

(a) Write algorithm and draw flow-chart to print even numbers from 1 to 100.

(b) Write a program to accept marks of four subjects as input from user. Calculate
and display total and percentage marks of student.

(c) Write a program to accept the value of year as input from the keyboard &
print whether it is a leap year or not.

(d) Write a program to accept a string as input from user and determine its length.
[Don’t use built in library function strlen( )]

(e) Write a program to swap two numbers using call by value.

5. Attempt any TWO of the following : 12

(a) Write a program using switch statement to check whether entered character is
VOWEL or CONSONANT.

(b) Write a program for addition of two 3  3 matrices.

(c) Write a program to Print values of variables and their addresses.

6. Attempt any TWO of the following : 12

(a) Write a program to declare structure employee having data member name,
age, street and city. Accept data for two employees and display it.

(b) If the value of a number (N) is entered through keyboard. Write a program
using recursion to calculate and display factorial of number (N).

(c) Write a program to accept two numbers from user and perform addition,
subtraction, multiplication and division operations using pointer.

_______________

P.T.O.
22226 [4 of 4]
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2018 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 any equivalent 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.

Q. Sub Answer Marking


No Q.N. Scheme
.
1. Attempt any FIVE of the following: 10
(a) Define Algorithm 2M
Ans Algorithm:- Algorithm is a stepwise set of instructions written to Correct
perform a specific task. Definitio
n 2M
(b) Give the significance of <math.h> and <stdio.h> header files. 2M
Ans “math.h” header file supports all the mathematical related functions Signific
in C language. ance of
stdio.h header file is used for input/output functions like scanf and each 1M
printf.
(c) Give syntax of if-else ladder. 2M
Ans if(condition_expression_One) Correct
{ syntax
statement1; 2M
}
else if (condition_expression_Two)
{
statement2;

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

}
else if (condition_expression_Three)
{
statement3;
}
else
{
statement4;
}
(d) Define Array. 2M
Ans An array is a collection of data items, all of the same type, accessed Definitio
using a common name. n of
A one-dimensional array consists of similar type of multiple values array
in it. 2M
A two dimensional array consists of row and column.

(e) Write syntax and use of pow ()function of <math.h> header file. 2M
Ans pow()- compute the power of a input value Syntax
Syntax: and use
double pow (double x, double y); of pow()
1M each
(f) Define pointer. Write syntax for pointer declaration. 2M
Ans Definition: Definitio
A pointer is a variable that stores memory address of another variable n of
which is of similar data type. pointer
Declaration: 1M,
datatype *pointer_variable_name; Syntax
1M
(g) Draw and label symbols used in flow chart. 2M

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

Any
Ans Four
Symbols
½M
each

2. Attempt any THREE of the following: 12


(a) Write an algorithm to determine whether a given number is 4M
divisible by 5 or not Correct
Ans Step 1- Start algorith
Step 2- Read / input the number. m 4M
Step 3- if n%5==0 then goto step 5.
Step 4- else number is not divisible by 5 goto step 6.
Step 5- display the output number is divisible by 5.
Step 6- Stop
(b) Explain do-while loop with example. 4M
Ans Do-While statement:
 In some applications it is necessary to execute the body of the loop
before the condition is checked; such situation can be handled by Explana
do statement. tion 2M,
 At least once the body of loop will be executed.
 do statement, first executes the body of the loop.
 At the end of the loop, the test condition in the while statement is
evaluated. If the condition is true, then it continues to execute body

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

of the loop once again.


 This process continues as long as the condition is true.
 When the condition becomes false, the loops will be terminated
and the control goes to next statement after while statement.

Example:
#include <stdio.h>
#include <conio.h> Any
void main() relevant
{ Example
int i=1; 2M
clrscr();
printf("\n Odd numbers from 1 to 20 are \n");
do
{
if(i%2 ! = 0)
printf("\n %d", i);
i++;
}while(i<=20); /* The loop iterates till the value of i is less than or
equal to 20 */
getch();
}
(c) Explain one dimension and two dimension arrays 4M
Ans i) One dimensional array:
An array is a collection of variables of the same type that are referred Explana
through a common name. A specific element in an array is accessed tion of
by an index. In C, all arrays consist of contiguous memory locations. one
The lowest address corresponds to the first element and the highest dimensi
address to the last element. onal and
Syntax: data_type array_name[array_size]; two
Example: dimensi
int marks[10]; onal
array
ii) Two dimensional array : 2M each
Two dimensional array is a collection of similar type of data elements
arranged in the form of rows & columns.
Example:
Array can be declared as int arr[3][3]; In this there can be 9 elements
in an array with 3 rows and 3 columns.

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

(d) Write the output of following c program 4M


#include<stdio.h>
int main()
{
char *ptr;
char str[]=”MAHARASHTRA STATE BOARD OF
TECHNICAL EDUCATION”;
ptr=str;
ptr=ptr+11;
printf(“%s”, ++ptr);
return 0; Correct
} output
Ans Output : 4M
STATE BOARD OF TECHNICAL EDUCATION

3 Attempt any THREE of the following: 12


(a) Explain increment and decrement operator. 4M
Ans Increment operator is used to increment or increase the value of a
variable by one. It is equivalent to adding one to the value of the Explana
variable. The symbol used is ++. The decrement operator is used to tion of
decrement or decrease the value of variable by 1. It is equivalent to each
subtracting one from the value of the variable. The symbol used is --. 2M
Syntax: ++var or var++ for increment and --var or var--for
decrement.

Example:
int m=5;
int n = ++m;
printf(%d%d”,m,n);
When the increment operator is used prior to the variable name m, the
value of the variable m is incremented first and then assigned to the
variable n. The values of both the variable m and n here will be 6. But
if the increment operator ++ is used after the variable name, then the
value of the variable m is assigned to the variable n and then the
value of m is increased. Therefore the values of m and n will be 6 and
5 respectively.
Example for decrement operator
int m=5;
int n=--m;

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

printf(“%d%d”,m,n);

or
#include<stdio.h>
#include<conio.h>
void main() {
int m=4,n=6;
clrscr();
printf("values of m and n before changing%d%d",m,n);
m++;
n--;
printf("\nvalues after changing%d%d",m,n);
getch();
}
(b) Explain User defined function with example. 4M
Ans Functions are basic building blocks in a program. It can be
predefined/ library functions or user defined functions. Predefined Explana
functions are those which are already available in C library. User tion with
defined functions are those which are written by the users to complete general
a specific task. Execution of a C program starts from main(). User syntax
defined functions should be called from main() for it to execute. A 2M
user defined function has a return type and a name. it my or may not
contain parameters. Example
The general syntax of a user defined function : 2M
Return_type func_name(parameter list)

Example:
#include<stdio.h>
#include<conio.h>
void myFunc(int a) {
printf("The value is: %d",a);
}
void main() {
myFunc(10);
getch()
}

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

(c) Explain conditional operator with example. 4M


Ans Conditional operators return one value if condition is true and returns
another value is condition is false. This operator is also called as Explana
ternary operator as it takes three arguments. tion 2M
Syntax :
(Condition? true_value: false_value); Example
2M
Example:
#include<stdio.h>
#include<conio.h>
void main() {
int i;
clrscr();
printf("Enter a number:");
scanf("%d",&i);
i%2==0?printf("%d is even",i):printf("%d is odd",i) ;
getch();
}
(d) Explain strlen() and strcpy() function with example. 4M
Ans strlen()- this function is used to find the length of a string. It counts
the number of characters comprising the string. Explan
Syntax: ation &
strlen(char[] str)- finds the length of the string str. Exampl
e of
Example: each
#include<stdio.h> 2M
#include<conio.h>
#include<string.h>
void main() {
char str[] = "mystring";
int len=0;
clrscr();
len=strlen(str);
printf("Length of string is :%d",len);
getch();
}

Strcpy()– this function is used to copy the contents of a string to


other.

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

Syntax:
strcpy(char[] dest, char[] source)- copies the contents of the string
source to destination.

Example:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main() {
char source[]="mystring";
char dest[10];
clrscr();
printf("%s%s",source,dest);
strcpy(dest,source);
printf("\n%s %s",source, dest);
getch();
}

4 Attempt any THREE of the following 12


(a) Write algorithm and draw flow-chart to print even numbers 4M
from 1 to 100.
Ans Algorithm Algorith
1. Start m 2M
2. Initialize the variable i to 1.
3. while i<=100 Flowcha
4. if i%2==0 rt 2M
5. print the number
6. increment value of i
7. stop

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

Flowchart

start

Initialize variable i=1

Is i <=100? NO

YES

Is i%2==0?
NO

YES
Print i

i=i+1

stop

(b) Write a program to accept marks of four subjects as input from 4M


user. Calculate and display total and percentage marks of
student.
Note: Any other correct logic shall be considered Relevant
Ans #include<stdio.h> logic
#include<conio.h> 2M
void main() {
float marks[4];
float total=0.0, perc=0.0; Syntax
int i; 2M

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

clrscr();
for(i=1;i<=4;i++) {
printf("Enter marks of subject %d",i);
scanf("%f%",&marks[i]);
}
for(i=1;i<=4;i++){
total=total+marks[i];
}
printf("Total is :%f",total);
perc=total/4;
printf("Percentage is %f",perc);
getch();
}
(c) Write a program to accept the value of year as input from the 4M
keyboard & print whether it is a leap year or not.
Ans #include<stdio.h> Correct
#include<conio.h> Logic
void main() { 2M
int year;
clrscr(); Correct
printf("Enter year"); Syntax
scanf("%d",&year); 2M
if(year%4==0) {
printf("Year %d is a leap year",year);
} else {
printf("Year %d is not a leap year",year);
}
getch();
}

(d) Write a program to accept a string as input from user and 4M


determine its length. [Don’t use built in library function strlen()]
Ans #include<stdio.h> Correct
#include<conio.h> Logic
void main(){ 2M
char str[50];
int i, len=0; Correct
clrscr(); Syntax
printf("Enter a string"); 2M

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

scanf("%s",&str);
for(i=0; str[i]!='\0'; i++){
len++;
}
printf("The length of string is %d",len);
getch();
}

(e) Write a program to swap two numbers using call be value. 4M


Ans #include<stdio.h>
#include<conio.h> Correct
void swap(int a, int b) { Logic
int temp; 2M
temp=a;
a=b; Correct
b=temp; Syntax
printf("Numbers after swapping no1=%d and no2=%d",a,b); 2M
}
void main() {
int no1, no2;
clrscr();
printf("Enter the 2 numbers");
scanf("%d%d",&no1,&no2);
printf("Numbers before swapping no1=%d and no2= %d",no1, no2);
swap(no1,no2);
getch();
}
5 Attempt any TWO of the following: 12
(a) Write a program using switch statement to check whether 6M
entered character is VOWEL or CONSONANT
Note : Assume that the entered character is only alphabet.
Ans #include<stdio.h>
#include<conio.h>
void main()
{ characte
char ch; r input-
clrscr(); 2M
printf("Enter character:");
scanf("%c",&ch);

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U': Display
printf("\n Entered character is VOWEL"); vowel-
break; 2M
default:
printf("\n Entered character is CONSONANT"); Display
} consona
getch(); nt
} 2M

(b) Write a program for addition of two 3 x 3 matrices. 6M


Ans #include<stdio.h>
#include<conio.h> Input of
void main() two
{ matrices
int a[3][3],b[3][3],c[3][3],i,j; 2M
clrscr();
printf("Enter first matrix elements:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nEnter second matrix elements:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

{
scanf("%d",&b[i][j]); Addition
} of
} matrices
for(i=0;i<3;i++) 2M
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("\n\nAddition of two matrices is:");
for(i=0;i<3;i++) Display
{ of
for(j=0;j<3;j++) addition
{ 2M
printf("%d\t",c[i][j]);
}
}
getch();
}
(c) Write a program to Print values of variables and their addresses. 6M
Note : 1) Variables can be of any data type.
2)Use of & or pointer to display address shall be
considered.
#include<stdio.h>
Ans #include<conio.h>
void main() Display
{ values
int a,b; of
clrscr(); variable-
a=5; 3M
b=10;
printf("\n Value of a=%d",a); Display
printf("\n Address of a=%u",&a); address
printf("\n Value of b=%d",b); of
printf("\n Address of b=%u",&b); variable
getch(); 3M
}

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

6 Attempt any TWO of the following: 12


(a) Write a program to declare structure employee having data 6M
member name, age, street and city. Accept data for two
employees and display it.
Note : Two structure variables or array of structure variables shall
be considered.
Ans #include<stdio.h>
#include<conio.h> Declarat
struct employee ion of
{ structur
char name[10],street[10],city[10]; e-2M
int age;
}; Acceptin
void main() g data-
{ 2M
int i;
struct employee e[2]; Displayi
clrscr(); ng
for(i=0;i<2;i++) data2M
{
printf("\n Enter name:");
scanf("%s",&e[i].name);
printf("\n Enter age:");
scanf("%d",&e[i].age);
printf("\n Enter street:");
scanf("%s",&e[i].street);
printf("\n Enter city:");
scanf("%s",&e[i].city);
}
for(i=0;i<2;i++)
{
printf("\n Name=%s",e[i].name);
printf("\n Age=%d",e[i].age);
printf("\n Street=%s",e[i].street);
printf("\n City=%s",e[i].city);
}
getch();
}

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

(b) If the value of a number (N) is entered through keyboard. Write 6M


a program using recursion to calculate and display factorial of
number (N).
Ans #include<stdio.h>
#include<conio.h>
int factorial(int N); Main
void main() function
{ definitio
int N,fact; n-3M,
clrscr();
printf("Enter number:");
scanf("%d",&N);
fact=factorial(N); Recursiv
printf("\n Factorial is:%d",fact); e
getch(); function
} definitio
int factorial(int N) n-3M
{
if(N==1)
return(1);
else
return(N*factorial(N-1));
}
(c) Write a program to accept two numbers from user and perform 6M
addition, subtraction, multiplication and division operations
using pointer.
Ans #include<stdio.h> Acceptin
#include<conio.h> g
void main() numbers
{ 1M
int no1,no2,*ptr1,*ptr2,result;
clrscr();
printf("Enter no1:"); Pointer
scanf("%d",&no1); initializa
printf("\nEnter no2:"); tion-1M
scanf("%d",&no2);
ptr1=&no1; Addition
ptr2=&no2; 1M
result=*ptr1+*ptr2;

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

WINTER – 2018 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

printf("\n Addition=%d",result); subtracti


result=*ptr1-*ptr2; on-1M
printf("\n Subtraction=%d",result);
result=*ptr1**ptr2; multiplic
printf("\n Multiplication=%d",result); ation-
result=*ptr1/(*ptr2); 1M
printf("\n Division=%d",result);
getch(); division-
} 1M

Page 16 / 16
21819
22226
3 Hours / 70 Marks Seat No.

Instructions : (1) All Questions are compulsory.


(2) Answer each next main Question on a new page.
(3) Illustrate your answers with neat sketches wherever necessary.
(4) Figures to the right indicate full marks.
(5) Assume suitable data, if necessary.
(6) Use of Non-programmable Electronic Pocket Calculator is permissible.

Marks
1. Attempt any FIVE of the following : 10
(a) Draw flowchart for checking whether given number is even or odd.
(b) List any four keywords used in ‘C’ with their use.
(c) Write the syntax of switch case statement.
(d) State any two differences between while and do-while statement.
(e) State difference between array and string.
(f) Declare a structure student with element roll-no and name.
(g) Distinguish between call by value and call by reference.

2. Attempt any THREE of the following : 12


(a) State four arithmetic operations perform on pointer with example.
(b) Draw flowchart for checking weather given number is prime or not.
(c) Write a program to reverse the number 1234 (i.e. 4321) using function.
(d) Differentiate between character array and integer array with respect to size
and initialisation.

[1 of 2] P.T.O.
22226 [2 of 2]
3. Attempt any THREE of the following : 12
(a) Write a program to sum all the odd numbers between 1 to 20.
(b) Explain any four bit-wise operator used in ‘C’ with example.
(c) With suitable example, explain how two dimensional arrays can be created.
(d) Explain any two string functions with example.

4. Attempt any THREE of the following : 12


(a) Draw flowchart for finding largest number among three numbers.
(b) Describe generic structure of ‘C’ program.
(c) Write a program to take input as a number and reverse it by while loop.
(d) Write a program to accept 10 numbers in array and arrange them in ascending
order.
(e) Explain meaning of following statement with reference to pointers :
int *a, b;
b = 20;
*a = b;
A = &b;

5. Attempt any TWO of the following : 12


(a) Write a program to perform addition, subtraction, multiplication and division
of two integer number using function.
(b) Define Array. Write a program to accept ten numbers in array. Sort array
element and display.
(c) Write a program to print reverse of a entered string using pointer.

6. Attempt any TWO of the following : 12


(a) Explain recursion with suitable example. List any two advantages.
(b) Write a program to accept ten numbers and print average of it.
(c) Enlist different format specifiers with its use.
_______________
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 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 any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant

answer.
6) In case of some questions credit may be given by judgement on part of examiner of relevant
ding.
7) For programming language papers, credit may be given to any other program based on
equivalent concept.

Q. Sub Answer Marking


No Q.N. Scheme
.
1. Attempt any FIVE of the following: 10
(a) Draw flowchart for checking whether given number is even or 2M
odd.
Ans.

Correct
logic 1M

Relevant
symbol
1M
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

(b) 2M
( ).
Ans.
Keyword Use
auto It is used to declare auto storage class variable.
break It is used to exit from block or loop.
case It is used to represent possible case inside switch Any
case statement four
char Used for declaration of character type variable keyword
const It is used to declare a constant. s 1M
continue It is used pass control at the beginning of the
loop Use 1M
default It is used to represent default case inside switch
case statement.
do It is used to execute loop in association with
while condition.
double Used for declaration of double type variable
else It is used with if statement to transfer control to
statement when condition is false.
enum It is used to declare enumerated data.
extern It is used to declare extern storage class variable
float Used for declaration of float type variable
for Used for repetitive execution of statements
goto It is used to transfer control from one statement
to another
if It is used for condition checking
int Used for declaration of integer type variable
long Used for declaration of long type variable
register It is used to declare register storage class
variable
return It is used to return value from function.
short Used for declaration of short type variable
signed Used for declaration of signed type variable
sizeof It returns memory size allocated to variable or
data type
static It is used to declare static storage class variable
struct It is used to declare user defined data type
structure
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

switch It is used to make decision from multiple number


of inputs
typedef Used to redefine the name of an existing variable
type.
union It is used to declare the data type union
unsigned Used for declaration of unsigned type variable
void Specify that function does not return any value
volatile It is used to declare a volatile variable
while Used for repetitive execution of statements

(c) Write the syntax of switch case statement. 2M


Ans. switch(variable)
{
case value1:
statements
break;
case value2: Correct
statements; syntax
break; 2M
.
.
.
default:
statements;
break;
}
(d) State any two differences between while and do-while statement. 2M
(Note: Any 2 points shall be considered).
Ans. while Do-while
In 'while' loop the controlling In 'do-while' loop the
condition appears at the start of controlling condition appears at Any two
the loop. the end of the loop. differen
The iterations do not occur if, The iteration occurs at least ces 1M
the condition at the first once even if the condition is each
iteration, appears false. false at the first iteration.
It is an entry controlled loop It is an exit controlled loop
while(condition) { do {
body body
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

} }while(condition);
(e) State difference between array and string. 2M
(Note: Any two valid points shall be considered).
Ans. Array String
Array can be of any type like String can contain only
int, float, char. characters. Any two
Element Elements in an array Characters in string are accessed points
can be accessed using its sequentially from first to last. 1M for
position like a[2].s in an array each
can be accessed using its
position like a[2].
Array does not end with a null S \
character character.
Array size once declared cannot String size can be modified
be changed using pointer.
(f) Declare a structure student with element roll-no and name. 2M
Ans. struct student
{ Correct
int roll_no; declarati
char name[20]; on 2M
};
(g) Distinguish between call by value and call by reference. 2M
(Note: Any two points shall be considered).
Ans. Call by value Call by reference
A copy of actual arguments is The address of actual arguments is
passed to respective formal passed to formal arguments Any two
arguments. points
Actual arguments will remain safe, Alteration to actual arguments is 1M each
they cannot be modified possible within from called
accidentally. function; therefore the code must
handle arguments carefully else
you get unexpected results.
Address of the actual and formal Address of the actual and formal
arguments are different arguments are the same
Changes made inside the function Changes made in the function is
is not reflected in other functions reflected outside also.

2. Attempt any THREE of the following: 12


(a) State four arithmetic operations perform on pointer with 4M
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

example.
(Note: Code snippet shall be considered)
Ans. The pointer arithmetic is done as per the data type of the pointer. The
basic operations on pointers are
Increment:
It is used to increment the pointer. Each time a pointer is
incremented, it points to the next location with respect to memory
size .
Example,
If ptr is an integer pointer stored at address 1000,then ptr++ shows
1002 as incremented location for an int.It increments by two locations Each
as it requires two bytes storage. operatio
n with
Decrement: example
It is used to decrement the pointer. Each time a pointer is 1M
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.
Eg:
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.
Eg:
If ptr is an integer pointer stored at address 1004,
Then ptr-2 shows 1004-(2*2) = 1000 as decremented location for an
int.
(b) Draw flowchart for checking weather given number is prime or 4M
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

not.
Ans.

Correct
logic 2M

Symbols
2M

(c) Write a program to reverse the number 1234 (i.e. 4321) using 4M
function.
(Note: Any other correct logic shall be considered).
Ans. #include<stdio.h>
#include<conio.h>
void findReverse(); Correct
void main() syntax
{ 2M
findReverse();
} Correct
void findReverse() logic 2M
{
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

int num, res=0,ans=0;


clrscr();
printf("Enter the number");
scanf("%d", &num);
while(num!=0)
{
res=num%10;
ans=ans*10+res;
num=num/10;
}
printf("Reverse number is %d", ans);
getch();
}
(d) Differentiate between character array and integer array with 4M
respect to size and initialisation.
Ans. Parameter Character Array Integer Array
Size Last location in No extra location
character array is than the number of
filled with '\0' so the elements is required. Each
array size should be paramet
so declared that it er 2M
should have one last
location for '\0'
character.
Initialization Initialization can be Initialization can be
done like : done like :
char int arr[4]={1,2,3,4};
str[4]={'a','b','c','\0'};
char str[4]="abc";
3. Attempt any THREE of the following: 12
(a) Write a program to sum all the odd numbers between 1 to 20. 4M
(Note: Any other correct logic shall be considered).
Ans. #include<stdio.h>
#include<conio.h>
void main()
{
int sum=0,i; Correct
clrscr(); logic
for(i=1;i<=20;i++) 2M
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

{
if(i%2==1)
sum=sum+i; Correct
} syntax
2M
getch();
}
(b) Explain any four bit- 4M
Ans. Bitwise operators:

Bitwise OR | Explana
It takes 2 bit patterns and performs OR operations on each pair of tion with
corresponding bits. The following example will explain it. example
1010 of any
1100 four
-------- bitwise
OR 1110 operator
1M each
Bitwise AND &
It takes 2 bit patterns and performs AND operations with it.
1010
1100
-------
AND 1000
-------
The Bitwise AND will take pair of bits from each position, and if
only both the bit is 1, the result on that position will be 1. Bitwise
AND is used to Turn-Off bits.
Bitwise NOT
One s complement operator (Bitwise NOT) is used to convert each
-bit to 0- -bit to1-
unary operator i.e. it takes only one operand.
1001
NOT 0110
-------

Bitwise XOR ^
Bitwise XOR ^, takes 2 bit patterns and perform XOR operation with
it.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

0101
0110
------
XOR 0011
------

Left shift Operator <<


The left shift operator will shift the bits towards left for the given
number of times.
int a=2<<1;

Right shift Operator >>


The right shift operator will shift the bits towards right for the given
number of times.
int a=8>>1;
(c) With suitable example, explain how two dimensional arrays can 4M
be created.
Ans. The array which is used to represent and store data in a tabular form
is called as two dimensional array. Such type of array is specially
used to represent data in a matrix form.
Declaration of two dimensional arrays:
Syntax:-
Data type arrayname [row size] [column size]; Explana
Eg: tion 2M
int arr[3][4];
and 4 columns.
A two-dimensional array can be considered as a table which will have
x number of rows and y number of columns. A two-dimensional array
a, which contains three rows and four columns can be shown as
follows
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

Thus, every element in the array a is identified by an element name of


the form a[i ][ j ], where 'a' is the name of the array, and 'i' and 'j' are
the subscripts that uniquely identify each element in 'a'.

Example :
main()
{
int a[2][2]={{1,2},{4,5});
int i,j; Example
for(i=0;i<2;i++) 2M
{
for(j=0;j<2;j++)
{

}
\
}
}
(d) Explain any two string functions with example. 4M
Ans. Strlen function:
strlen( ) function in C gives the length of the given string. strlen( )
function counts the number of characters in a given string and returns Explana
the integer value. It stops counting the character when null character tion of
is found. Because, null character indicates the end of the string in C. any two
Syntax: string
strlen(stringname); function
Example: s 1M
each,
strlen(str1); returns length of str1 as 3 example
1M each
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

strcat() function:
In C programming, strcat() concatenates (joins) two strings. It
concatenates source string at the end of destination string.
Syntax:
strcat( destinationsource, source string);
Example:

strcat(str1,str2); returns abcdef in str1 and str2 remains unchanged.

strcpy() function
strncpy( ) function copies portion of contents of one string into
another string.
Syntax:
strncpy( destination string, source string, size );
Example:

strcpy(str1,str2); returns abcstr2

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);
Example:

Then strcmp(str1,str2) returns 0 as both the strings are same.


4. Attempt any THREE of the following: 12
(a) Draw flowchart for finding largest number among three 4M
numbers.
Ans.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

Correct
flowchar
t 4M

(b) 4M
Ans.

List of
sections
from
structur
e 1M
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

Documentation section: The documentation section consists of a set


of comment lines giving the name of the program, the author and
other details, which the programmer would like to use later.
Correct
Link section: The link section provides instructions to the compiler descripti
to link functions from the system library such as using the #include on of
directive. structur
e 3M
Definition section: The definition section defines all symbolic
constants such using the #define directive.

Global declaration section: There are some variables that are used in
more than one function. Such variables are called global variables and
are declared in the global declaration section that is outside of all the
functions.

Declaration part: The declaration part declares all the variables used
in the executable part.

Subprogram section: If the program is a multi-function program


then the subprogram section contains all the user-defined functions
that are called in the main () function. User-defined functions are
generally placed immediately after the main () function, although
they may appear in any order.

Header files
A header file is a file with extension .h which contains C function
declarations and macro definitions to be shared between several
source files.

Include Syntax
Both the user and the system header files are included using the
preprocessing directive #include.

main() function is the entry point of any C program. It is the point at


which execution of program is started. Every C program have a
main() function.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

(c) Write a program to take input as a number and reverse it by 4M


while loop.
(Note: Any other correct logic shall be considered).
Ans. #include<stdio.h>
#include<conio.h>
void main() Accept
{ input
int no; 1M
int sum=0,rem;
printf("\n Enter number:"); Use of
scanf("%d",&no); while
while(no>0) loop 1M
{
rem=no%10; correct
no=no/10; syntax
sum=sum*10+ rem; 2M
}
printf("\nsum=%d",sum);
getch();
}
(d) Write a program to accept 10 numbers in array and arrange 4M
them in ascending order.
(Note: Any other correct logic shall be considered).
Ans. #include<stdio.h>
#include<conio.h>
void main()
{
int arr[10],i,j,temp; Correct
clrscr(); logic
printf("Enter array elements:"); 2M
for(i=0;i<10;i++)
{ Correct
scanf("%d",&arr[i]); syntax
} 2M
printf("\n\n Array elements are:");
for(i=0;i<10;i++)
{
printf("%d ",arr[i]);
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

}
for(j=0;j<10;j++)
{
for(i=0;i<10;i++)
{
if(arr[i+1]<arr[i])
{
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
}
printf("\n\nArray elements in ascending order are:");
for(i=0;i<10;i++)
{
printf("%d ",arr[i]);
}
getch();
}

(e) Explain meaning of following statement with reference to 4M


pointers:
int *a, b;
b=20;
*a=b;
A=&b;
Ans.
int *a,b;
It is declaration of integer pointer a and integer variable b

b=20; Correct
value 20 is assigned to variable b. meaning
of each
*a=b; statemen
Value of b is assigned to pointer a. t 1M

A=&b;
Address of b is assigned to variable A.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

5. Attempt any TWO of the following: 12


(a) Write a program to perform addition, subtraction, multiplication 6M
and division of two integer number using function.
(Note: Any other correct logic shall be considered).
Ans. #include<stdio.h>
#include<conio.h>
void add(int x,int y)
{ Add
printf("\nAddition=%d",x+y); function
} 1M
void sub(int x,int y)
{ sub
printf("\nSubtraction=%d",x-y); function
} 1M
void mult(int x,int y)
{ Mult
printf("\nMultiplication=%d",x*y); function
} 1M
void div(int x,int y)
{ Div
printf("\nDivision=%d",x/y); function
} 1M
void main()
{ Main
intx,y; function
clrscr(); 2M
printf("Enter x:");
scanf("%d",&x);
printf("Enter y:");
scanf("%d",&y);
add(x,y);
sub(x,y);
mult(x,y);
div(x,y);
getch();
}
(b) Define Array. Write a program to accept ten numbers in array. 6M
Sort array element and display.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

Ans.
Definition of Array:
An array is a collection of data elements, all of the same type, Array
accessed using a common name. definitio
n 1M
Program:
#include<stdio.h>
#include<conio.h>
void main()
{ Acceptin
int a[10],i,j,temp; g array
clrscr(); 1M
printf("Enter numbers:");
for(i=0;i<10;i++) Sorting
scanf("%d",&a[i]); logic 3M
for(i=0;i<10;i++)
{ Display
for(j=i+1;j<10;j++) sorted
{ array
if(a[i]>a[j]) 1M
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\n Sorted array elements:");
for(i=0;i<10;i++)
printf("\n %d",a[i]);
getch();
}
(c) Write a program to print reverse of a entered string using 4M
pointer.
(Note: Any other correct logic shall be considered).
Ans. #include<stdio.h>
#include<conio.h>
void main()
{
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

char str[10],*ptr;
int l=0;
clrscr(); Acceptin
printf("Enter string:"); g string
scanf("%s",str); 1M
ptr=str;
while(*ptr!='\0') pointer
{ initializa
l=l+1; tion1M
ptr=ptr+1;
}
while(l>0) logic of
{ reverse
ptr=ptr-1; using
printf("%c",*ptr); pointer
l=l-1; 3M
}
getch(); Displayi
} ng
reverse
string
1M
6. Attempt any TWO of the following: 12
(a) Explain recursion with suitable example. List any two 6M
advantages.
Ans. Recursion means a function calls itself repetitively. A recursive Explana
function contains a function call to itself inside its body. tion of
recursio
Example: n 1M
#include<stdio.h>
#include<conio.h>
int factorial(int N);
void main()
{
int N,fact; Example
clrscr(); 3M
printf("Enter number:");
scanf("%d",&N);
fact=factorial(N);
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

printf("\n Factorial is:%d",fact);


getch();
}
int factorial(int N)
{
if(N==1)
return(1);
else
return(N*factorial(N-1));
}

Advantages:
Reduces length of the program Any two
Reduces unnecessary calling of a function. Advanta
Useful when same solution is to be applied many times. ges 2M
(b) Write a program to accept ten numbers and print average of it. 6M
(Note: Program without array shall be considered).
Ans. #include<stdio.h> Acceptin
#include<conio.h> g 10
void main() numbers
{ 2M
int a[10],i,sum=0;
float avg; Calculat
clrscr(); ing
printf("Enter numbers:"); average
for(i=0;i<10;i++) 2M
scanf("%d",&a[i]);
for(i=0;i<10;i++) Displayi
sum=sum+a[i]; ng
avg=sum/10; average
printf("\n Average =%f", avg); 2M
getch();
}
(c) Enlist different format specifiers with its use. 6M
Ans. Format specifier tells the compiler what type of data a variable holds
during taking input and printing output using scanf() and printf()
functions respectively.
Format specifiers used in C programming:
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in C Subject Code: 22226

Format Use
specifier
%d Specify data type as short signed
%u Specify data type as short unsigned
%ld Specify data type as long singed Any six
%lu Specify data type as long unsigned format
%x Specify data type as unsigned hexadecimal specifier
%o Specify data type as unsigned octal s with
%f Specify data type as float use 1M
%lf Specify data type as double each
%Lf Specify data type as long double
%c Specify data type as signed character
%s Specify data type as unsigned group of
characters(Strings)
11920
22226
3 Hours / 70 Marks Seat No.

Instructions : (1) All Questions are compulsory.


(2) Answer each next main Question on a new page.
(3) Illustrate your answers with neat sketches wherever necessary.
(4) Figures to the right indicate full marks.
(5) Assume suitable data, if necessary.
(6) Mobile Phone, Pager and any other Electronic Communication
devices are not permissible in Examination Hall.

Marks
1. Attempt any FIVE of the following : 10
(a) Define array. List its type.
(b) Draw & label different symbols used in flowcharts.
(c) Find the output of the following program :
# include < stdio.h>
void main( )
{
int x = 10, y = 10, v1, v2 ;
v1 = x++ ;
v2 = ++y ;
printf ("value of v1:%d", v1) ;
printf ("value of v2:%d", v2) ;
}
(d) State the syntax & use of strlen ( ) & strcat ( ) function.
(e) State the Relational operators with example.
(f) State the syntax to declare pointer variable with example.
(g) Draw flow chart for addition of two numbers.
[1 of 2] P.T.O.
22226 [2 of 2]
2. Attempt any THREE of the following : 12
(a) State the importance of flow chart.
(b) Write a program to declare structure student having rollno, name & marks.
Accept & display data for 3 students.
(c) Explain pointer arithmetic with example.
(d) Explain nested if-else with example.

3. Attempt any THREE of the following : 12


(a) Describe the following terms :
(i) Keyword
(ii) Identifier
(iii) Variable
(iv) Constant
(b) Differentiate between call by value and call by reference.
(c) Explain conditional operator with example.
(d) List the categories of functions and explain any one with example.

4. Attempt any THREE of the following : 12


(a) Write an algorithm to determine the given number is odd or even.
(b) Illustrate the use of break and continue statement with example.
(c) Write a program to add, subtract, multiply and divide two numbers, accepted
from user using switch case.
(d) Illustrate initialization of two dimensional array with example.
(e) Write a program to read two strings and find whether they are equal or not.

5. Attempt any TWO of the following : 12


(a) Write a program to calculate sum of all the odd numbers between 1 to 20.
(b) Write a program for addition of two 3  3 matrices.
(c) Write a program to compute the sum of all elements stored in an array using
pointers.

6. Attempt any TWO of the following : 12


(a) Write a program to sort elements of an array in ascending order.
(b) Write a function to print Fibonacci series starting from 0, 1.
(c) Calculate factorial of a number using recursion.
_______________
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2019 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 any equivalent 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.

Q. Sub Answer Marking


No Q.N. Scheme
.
1. Attempt any FIVE of the following: 10
(a) Define array. List its type. 2M
Ans. Array is a fixed-size sequential collection of elements of the same
type. Definitio
n 1M
Types:
1. One dimensional
Types
2. Multi dimensional
1M
(b) Draw & label different symbols used in flowcharts. 2M
Ans.
Symbol Name Function
Start/end An oval represents a start or end Any 4
point symbols
½M
Arrows A line is a connector that shows each
relationships between the
representative shapes

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

Input/Output A parallelogram represents input


or output

Process A rectangle represents a process

Decision A diamond indicates a decision

(c) Find the output of the following program: 2M


#include<stdio.h>
void main( )
{
int x = 10, y = 10, v1, v2;
v1 = x++;
v2 = ++y;
printf(“value of v1: %d, v1);
printf(“value of v2: %d, v2);
}
Ans. Correct
Output: output
value of v1:10value of v2:11 2M
(d) State the syntax & use of strlen ( ) & strcat ( ) function. 2M
Ans. 1M for
strlen( ): calculates the length of the string correct
Syntax: strlen(s1); syntax
strcat():concatenates two strings 1M for
Syntax: strcat(s1,s2) use
(e) State the Relational operators with example. 2M
Ans. == - returns true if the values of two operands are equal else returns
false.
E.g: if (A= = B){ }
!= - returns true if values of two operands are not equal, else returns
Page 2 / 17
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

false
E.g: if (A! = B){ }
<- returns true if the first operand is less than the second, else returns Any
false. four
E.g: if (A< B){ } operator
>- returns true if the first operand is greater than the second, else s ½M
returns false. each
E.g: if (A> B){ }
<= returns true if the first operand is less than or equal to the second,
else returns false.
E.g: if (A< = B){ }
>= returns true if the first operand is greater than or equal to the
second, else returns false.
E.g: if (A> = B){ }
(f) State the syntax to declare pointer variable with example. 2M
Ans. Correct
General syntax to declare pointer. syntax
datatype *var_name; 1M
Correct
Eg: int var = 20; example
1M
(g) Draw flow chart for addition of two numbers. 2M
Ans.

Correct
sequenc
e 1M

Correct
symbol
1M

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

2. Attempt any THREE of the following: 12


(a) State the importance of flow chart. 4M
Ans. A flowchart is a type of diagram that represents an algorithm. It is a
visual representation of a sequence of steps to complete the process.
A flow chart describes a process using symbols rather than words.
Computer programmers use flow charts to show where data enters the
program, what processes the data goes through, and how the data is
converted to output.
-can be used to quickly communicate the ideas or plans that one
programmer envisions to other people who will be involved in the Any 4
process. points
- aid in the analysis of the process to make sure nothing is left out and 1M each
that all possible inputs, processes, and outputs have been accounted
for.
-help programmers develop the most efficient coding because they
can clearly see where the data is going to end up.
- help programmers figure out where a potential problem area is and
helps them with debugging or cleaning up code that is not working.
- are a useful tool in visualizing a module's flow of execution before
writing any code. This allows developers to do three things: verify the
algorithm's correctness before writing code, visualize how the code
will ultimately be written, and communicate and document the
algorithm with other developers and even non-developers.
-may be used in conjunction with other tools, such as pseudo-code, or
may be used by itself to communicate a module's ultimate design,
depending on the level of detail of the flowchart.
(b) Write a program to declare structure student having rollno, 4M
name & marks.
(Note: Any other correct logic shall be considered).
Ans. Accept and display data for three students.
#include<stdio.h>
#include<conio.h>
void main() { Correct
int i; logic 3M
struct student{
int rollno;
char name[20]; Correct
int marks; syntax
} s[3]; 1M

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

clrscr();
for(i=0;i<3;i++) {
printf("Enter rollno, name and marks\n");
scanf("%d%s%d",&s[i].rollno,&s[i].name,&s[i].marks);
}
for(i = 0; i<3;i++){
printf("\nThe details of student %d\n",i+1);
printf("Roll no %d\n",s[i].rollno);
printf("Name is %s\n",s[i].name);
printf("Marks %d\n",s[i].marks);
}
getch();
}
(c) Explain pointer arithmetic with example. 4M
(Note: Code snippet shall be considered).
Ans. The pointer arithmetic is done as per the data type of the pointer. The
basic operations on pointers are:
Increment
It is used to increment the pointer. Each time a pointer is Any two
incremented, it points to the next location. Eg, for an int pointer operator
variable, if the current position of pointer is 1000, when incremented s
it points to 1002 because for storing an int value it takes 2 bytes of
memory. Each
operator
Decrement with
It is used to decrement the pointer. Each time a pointer is explanat
decremented, it points to the previous location. Eg, if the current ion 1M
position of pointer is 1002, then decrement operation results in the
pointer pointing to the location 1000.
1M for
Addition and subtraction: each
When addition or subtraction operation is performed on the pointer example
variable, it shows that particular location in the memory.
Eg: int *ptr; -say address is 1000.
If -> ptr+n- then ptr+n*2 .
If -> ptr-n thenptr-n*2.
#include<stdio.h>
#include<conio.h>
void main() {

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

int i = 10;
int *ptr=&i;
clrscr();
printf("%x%d",ptr,i);
ptr++;
printf("\n%x%d",ptr,i);
printf("\n%x",ptr+2);
printf("\n%x",ptr-2);
getch();
}
(d) Explain nested if-else with example. 4M
(Note: Any example shall be considered)
Ans. When a series of decision is required, nested if-else is used. Nesting
means using one if-else construct within another one. If the condition
in the outer if, is true, then only the inner if-else will get executed.
Further the statements in the inner if will get execute only if the
condition of inner if, evaluates to true. If it is false, the statements in Explana
inner else will get executed. tion 2M
If the outer if evaluates to false, then the statements in outer else get
executed.

General syntax:
if(condition) {
if(condition) {
statements
} else {
statements
}
} else {
statements
}
statements

Example:
#include<stdio.h>
#include<conio.h>
void main() { Example
int val; 2M
clrscr();

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

printf("Enter a number");
scanf("%d",&val);
if(val>=5) {
if(val>5) {
printf("Number is greater than 5");
} else {
printf("Number is equal to 5");
}
} else {
printf("Number is less than 5");
}
getch();
}
3. Attempt any THREE of the following: 12
(a) Describe the following terms: 4M
(i) Keyword
(ii) Identifier
(iii) Variable
(iv) Constant
Ans. (i) Keyword: Keywords are special words in C programming which
have their own predefined meaning. The functions and meanings of
these words cannot be altered. Some keywords in C Programming
are if, while, for, do, etc.. Each
(ii) Identifier: Identifiers are user-defined names of variables, term 1M
functions and arrays. It comprises of combination of letters and digits.
Example
int age1;
float height_in_feet;
Here, age1 is an identifier of integer data type.
Similarly height_feet is also an identifier but of floating integer data
type,
(iii) Variable: A variable is nothing but a name given to a storage
area that our programs can manipulate. Each variable in C has a
specific type, which determines the size and layout of the variable's
memory; the range of values that can be stored within that memory;
and the set of operations that can be applied to the variable.
Example: add, a, name
(iv) Constant:

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

Constants refer to fixed values that the program may not change
during its execution. These fixed values are also called literals.
Constants can be of any of the basic data types like an integer
constant, a floating constant, a character constant, or a string literal.
There are enumeration constants as well.
Example:
121
234
3.14
(b) Differentiate between call by value and call by reference. 4M
Ans.
Sr. Call by value Call by reference
No.
1 When function is called When function is called by
by passing values then it passing address of variable then
is call by value it is called as call by reference.
2 Copy of actual variable is No copy is generated for actual
created when function is variable rather address of actual Any
called. variable is passed. four
3 In call by value, memory In call by reference, memory differen
required is more as copy required is less as there is no ces 1M
of variable is created. copy of actual variables. each
4 Example:- Example:-
Function call - Function call –
Swap ( x,y); Swap ( &x, &y );
Calling swap function by Calling swap function by
passing passing
values. address.
5 Original (actual) Actual parameters change as
parameters do not change. function operates on value
Changes take place on the stored at the address.
copy of variable.
(c) Explain conditional operator with example. 4M
Ans. Conditional Operator (Ternary Operator):
It takes the form „? :‟ to construct conditional expressions Explana
The operator „? :‟ works as follows: tion 2M
exp1 ? exp2 : exp 3
Where exp1, exp2 and exp3 are expressions.exp1 is evaluated first, If
it is true, then the expression exp2 is evaluated and becomes the value Example

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

of the expression. If exp1 is false, exp3 is evaluated and its value 2M


becomes the value of the expression.
E.g. int a=10,b=5,x;
x=(a>b) ? a : b;
(d) List the categories of functions and explain any one with example. 4M
Ans. Different categories of function:
1) Function with no arguments and no return value.
2) Function with arguments and no return value.
3) Function with no arguments and return value. List 2M
4) Function with arguments and return value.
1) Function with no arguments and no return value:
This category of function cannot return any value back to the calling
program and it does not accept any arguments also. It has to be
declared as void.
For example: Explana
void add() tion of
{ any one
inta,b,c; category
a=5; 2M
b=6;
c=a+b;
printf(“%d”,c);
}
It should be called as add();
2) Function with arguments and no return value:
This category of function cannot return any value back to the calling
program but it takes arguments from calling program. It has to be
declared as void. The number of arguments should match in
sequence, number and data type.
For example:
void add(intx,int y)
{
int z;
z=x+y;
printf(“%d”,z);
}
It should be called as add(4,5); where x will take 4 and y will take 5
as their values.

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

3) Function with no arguments and return value:


This category of function can return a value back to the calling
program but it does not take arguments from calling program. It has
to be declared with same data type as the data type of return variable.
For example:
int add()
{
inta,b,c;
a=5;
b=6;
c=a+b;
return(c);
}
It should be called as int x = add(); where x will store value returned
by the function.
4) Function with arguments and return value:
This category of function can return a value back to the calling
program but it also takes arguments from calling program. It has to be
declared with same data type as the data type of return variable.
For example:
int add(intx,int y)
{
int z;
z=x+y;
return(z);
}
It should be called as int s = add(4,5); where x will have 4 and y will
have 5 as their values and s will store value returned by the function.
4. Attempt any THREE of the following: 12
(a) Write an algorithm to determine the given number is odd or 4M
even.
Ans.
Step 1- Start
Step 2- Read / input the number. Correct
Step 3- if n%2==0 then number is even. algorith
Step 4- else number is odd. m 4M
Step 5- display the output.
Step 6- Stop
(b) Illustrate the use of break and continue statement with example. 4M

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

(Note:- Any other example shall be considered)


Ans. Break: It breaks the execution of the loop which allows exiting from
any loop or switch, such that break statement skips the remaining part
of current iterations of the loop.
Syntax: break; Use of
each 1M

Example
of each
1M
Continue: It is used when it is required to skip the remaining portion
of the loop without breaking loop it will transfer control directly to
next iteration
Syntax: continue;

In given program sequence if “break” executes then execution control


will jump out of loop & next statement after loop will be executed. In
given program sequence if “continue” executes then execution
control will skip remaining statements of loop & will start next
iteration of loop
(c) Write a program to add, subtract, multiply and divide two 4M
numbers, accepted from user switch case.
(Note: Any other correct logic shall be considered).
Ans. #include<stdio.h>
#include<conio.h> Correct
void main() logic 2M
{
int a,b,ch,add,sub,mul,div;
clrscr();
printf("\n1 for addition \n2 for substraction"); Correct
printf("\n3 for multiplication \n4 for division"); syntax
printf("\nEnter two numbers:"); 2M

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

scanf("%d%d",&a,&b);
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
add=a+b;
printf("Addition of a & b=%d",add);
break;
case 2:
sub=a-b;
printf("Substraction of a & b=%d",sub);
break;
case 3:
mul=a*b;
printf("Multiplication of two numbers=%d",mul);
break;
case 4:
div=a/b;
printf("Division of two numbers=%d",div);
break;
default:
printf("Invalid choice....");
}
getch();
}
(d) Illustrate initialization of two dimensional array with example. 4M
Ans. Two dimensional array:
The array which is used to represent and store data in a tabular form
is called as two dimensional array. Such type of array is specially Two dim
used to represent data in a matrix form. array
Initialization can be done as design time or runtime. 1M
1. Design time: This can be done by providing „row X column‟
number of elements to the array. Eg for a 3 rows and 4 columns array Declarat
, 3X4=12 elements can be provided as : ion 1M
arr[3][4]={ {2,3,4,6},
{1,4,6,3},
{6,6,4,3},
{6,7,8,9}
};

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

2. Runtime: For this loop structures like „for‟ can be used in a nested
form, where outer loop will increment row and inner loop will Initializ
increment column. ation by
Eg : any one
for(i=0;i<3;i++) type 1M
{
for(j=0;j<4;j++)
{
scanf(“%d”, &arr[i][j]);
}
}
Example:
main()
{
int arr[2][2]={{1,2},{4,5});
int i,j; Example
for(i=0;i<2;i++) 1M
{
for(j=0;j<2;j++)
{
printf( “%d”, arr[i][j]);
}
printf(“\n”);
}
}
(e) Write a program to read two strings and find whether they are 4M
equal or not.
(Note: Any other correct logic shall be considered).
Ans. #include<stdio.h> Correct
#include<conio.h> logic 2M
#include<string.h>
void main()
{
char st1[20],st2[20]; Correct
printf(“enter string 1”); syntax
scanf(“%s”,st1); 2M
printf(“enter second string”);
scanf(“%s”,st2);
if(strcmp(st1,st2)==0)

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

printf(“\nboth strings are equal”);


else
printf(“\nstrings are not equal”);
}
5. Attempt any TWO of the following: 12
(a) Write a program to calculate sum of all the odd numbers between 6M
1 to 20.
(Note: Any other correct logic shall be considered).
Ans. #include<stdio.h>
#include<conio.h> Finding
void main() odd
{ numbers
inti,sum=0; 2M
clrscr();
for(i=1;i<=20;i++) Calculat
{ ing sum
if(i%2!=0) 1M
{
sum=sum+i; Display
} sum 1M
}
printf("Sum=%d",sum); Correct
getch(); syntax
} 2M
(b) Write a program for addition of two 3 x 3 matrices. 6M
(Note: Any other correct logic shall be considered).
Ans. #include<stdio.h>
#include<conio.h>
void main()
{ Decelera
int a[3][3],b[3][3],c[3][3],i,j; tion of
clrscr(); variable
printf("\n Enter first matrix"); s 1M
for(i=0;i<3;i++)
{ Input
for(j=0;j<3;j++) matrices
{ 2M
scanf("%d",&a[i][j]);
}

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

}
printf("\n Enter second matrix");
for(i=0;i<3;i++)
{ Calculat
for(j=0;j<3;j++) ing
{ addition
scanf("%d",&b[i][j]); 2M
}
} Display
for(i=0;i<3;i++) addition
{ 1M
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();
}
(c) Write a program to compute the sum of all elements stored in an 6M
array using pointers.
(Note: Any other correct logic shall be considered).
Ans. #include<stdio.h>
#include<conio.h>
void main() Variable
{ declarati
int a[5],sum=0,i,*ptr; on 1M
clrscr();
printf("\n Enter array elements:"); Input
for(i=0;i<5;i++) array
scanf("%d",&a[i]); 1M

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

ptr=&a[0]; Pointer
for(i=0;i<5;i++) Initializ
{ ation
sum=sum+(*ptr); 1M
ptr=ptr+1; Sum
} calculati
printf("\n Sum= %d",sum); on 2M
getch(); Display
} 1M
6. Attempt any TWO of the following: 12
(a) Write a program to sort elements of an array in ascending order. 6M
(Note: Any other correct logic shall be considered).
Ans. #include<stdio.h>
#include<conio.h>
void main() Input
{ array
int a[5],i,j,temp; 1M
clrscr();
printf("\n Enter array elements:"); Sorting
for(i=0;i<5;i++) logic 4M
scanf("%d",&a[i]);
for(i=0;i<5;i++)
{ Display
for(j=0;j<4-i;j++) sorted
{ list 1M
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(i=0;i<5;i++)
printf("\n %d",a[i]);
getch();
}
(b) Write a function to print Fibonacci series starting from 0, 1. 6M
(Note: Any other correct logic shall be considered).

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

WINTER – 2019 EXAMINATION


MODEL ANSWER
Subject: Programming in 'C' Subject Code: 22226

Ans. void Fibbo()


{
inta,b,c,limit,i;
printf("\n Enter number:"); Correct
scanf("%d",&limit); function
a=0; with
b=1; syntax
printf("%d\t%d",a,b); 6M
for(i=0;i<limit-2;i++)
{
c=a+b;
printf("\t%d",c);
a=b;
b=c;
}
}
(c) Calculate factorial of a number using recursion. 6M
(Note: Explanation/algorithm/program shall be considered)
Ans. #include<stdio.h>
#include<conio.h>
int factorial(int no)
{
if(no==1)
return(1);
else Recursiv
return(no*factorial(no-1)); e
} function
void main() 4M
{
intfact,no;
clrscr(); Main
printf("\n Enter number"); function
scanf("%d",&no); 2M
fact=factorial(no);
printf("\n Factorial number=%d",fact);
getch();
}

Page 17 / 17
22226
21222
3 Hours / 70 Marks Seat No.
15 minutes extra for each hour

Instructions – (1) All Questions are Compulsory.


(2) Illustrate your answers with neat sketches wherever
necessary.
(3) Figures to the right indicate full marks.
(4) Assume suitable data, if necessary.
(5) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.

Marks

1. Attempt any FIVE of the following: 10


a) Draw and label different symbols used in flowchart.
b) List any four keywords used in ‘C’
c) State any four decision making statements.
d) Define array. List its types.
e) Write syntax and use of PQW ( ) function or <math.h>
header file.
f) State the syntax to declare a pointer variable with example.
g) Draw flowchart for addition of two numbers.

P.T.O.
22226 [2]
Marks
2. Attempt any THREE of the following: 12
a) Write an algorithm to find largest of three numbers.
b) Explain do while loop with example.
c) Differentiate between character array and integer array with
respect to size and initialisation.
d) Explain meaning of following statements with reference
to pointers
int *a, b ;
b = 20 ;
*a = b ;
a = &b ;

3. Attempt any THREE of the following: 12


a) Describe the following terms :
(i) Keyword
(ii) Identifier
(iii) Variable
(iv) Constant
b) List the categories of functions and explain any one with
example.
c) State the use of printf( ) and scanf( ) with suitable example.
d) Give any four differences between call by value and call by
reference.
22226 [3]
Marks
4. Attempt any THREE of the following: 12
a) Draw flowchart for finding largest number among three
numbers.
b) Write a program to display table of given number (Accept
number from user).
c) Write a program to sum all the even numbers between
1 to 100.
d) Develope a program to find the factorial of a number
using recursion.
e) Write a program to accept ten numbers in an array. Sort
array elements and display it.

5. Attempt any TWO of the following: 12


a) Write a program to print Fibonacci series starting from
0 and 1.
b) Write a program for addition of 3 × 3 matrices.
c) Write a program to compute the sum of all elements stored
in an array using pointers.

6. Attempt any TWO of the following: 12


a) Write a program using structure to display information of
employee which consist of employee id, name, age and salary.
b) Write a program to demonstrate use of strcmp( ), strcpy( ),
strlen( ), strcat( ).
c) Write a program to perform arithmetic operations on pointer.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
SUMMER – 2022 EXAMINATION
Subject Name: Programming in C Model Answer Subject Code: 22226
Important Instructions to examiners: XXXXX
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 any equivalent 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. Scheme
N.

1 Attempt any FIVE of the following: 10 M

a) Draw and label different symbols used in flowchart. 2M

Ans 4 symbols
with name-
each carry ½
M

b) List any four keywords used in 'C'. 2M

Ans Following are the keywords used in ‘C’: 4 keywords


½ M each

Page No: 1 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

c) State any four decision making statements. 2M

Ans Following are decision making statements: 4 decisions


making-
1. if statement.
2. if..else statements. ½ M each
3. nested if statements.
4. if-else-if ladder.
5. switch statements.
6. for loop
7. do..while loop
8. While loop
d) Define array. List its types. 2M

Ans ● Array is a collection of similar datatype elements stored at contiguous memory Definition of
locations. an array-1 M
● Array is a fixed-size sequential collection of elements of the same type.
● Arrays are the derived data type in C programming language which can store the Types of
primitive type of data such as int, char, double, float, etc array (any
Types of Array: 2)-1 M
1. One Dimensional
2. Two Dimensional
3. multi-Dimensional
e) Write syntax and use of PQW ( ) function or <math.h> header file. 2M

Ans Pow(): any one


compute the power of a input value. written
Syntax: double pow (double x, double y); should be
Example: pow(2,4); // returns 16 given 2
<math.h> header file declares a set of functions to perform mathematical operations marks
such as: sqrt() to calculate the square root, log() to find natural logarithm of a number etc.
Syntax: #include<math.h>

Page No: 2 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
f) State the syntax to declare a pointer variable with example. 2M

Ans Syntax: datatype *pointer_variable_name; Syntax to


Example: int *p; declare -1M
Example-1
Initialization Syntax: pointer = &variable; M
Initialization Example:
int a; // Step 1
int *p; // Step 2
a = 10; // Step 3
p= &a; // Step 4
g) Draw flowchart for addition of two numbers. 2M

Ans Appropriate
flowchart 2
marks

2. Attempt any THREE of the following: 12 M

a) Write an algorithm to find largest of three numbers. 4M

Ans Algorithm for finding the largest among them: Start and
stop: 1M
Step 1: Start
Step 2: Declare three integer variables a, b, c Declaring
Step 3: If a is greater than b, variable: 1
if a is greater than c, M
Print "a is largest"
Logic: 2M
else
Print "c is largest"
else
if b is greater than c,
Page No: 3 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Print "b is largest"
else
Print "c is largest"
Step 4: Stop
b) Explain do while loop with example. 4M

Ans Use: Use: 1M


In 'do-while' loop the controlling condition appears at the end of the loop.
The iteration occurs at least once even if the condition is false at the first iteration. Syntax: 1M
It is an exit controlled loop. Example:
Syntax: 1M
do
{ Flowchart:1
//executable code; M
} while(condition);

Flowchart for do…while loop:

Example:
#include<stdio.h> Output:
void main()
{
int n;
n=1; //Initialize
do
{
printf("%d\n",n);
n++; // Increment
}while(n<=10); //while loop
}
c) Differentiate between character array and integer array with respect to size 4M
and initialisation.

Size: 2 M

Page No: 4 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans Initialization
Parameter Character Array Integer Array :2M

Size Size Last location in character No extra location than the number
array is filled with '\0' so the of elements is required.
array size should be so declared
that it should have one last
location for '\0' character.

definition A char array is an object An integer array is an object capable


capable of holding values of of holding values of type int.
type char.

Initialization Initialization can be done like : Initialization can be done like :


char str[4]={'a','b','c','\0'}; int arr[4]={1,2,3,4};
char str[4]="abc";

d) Explain meaning of following statements with reference to pointers 4M

int *a, b ;

b = 20 ;

*a = b ;

a = &b ;

Ans int *a,b; Each


It is declaration of integer pointer a and integer variable b. statement:
1M
b=20;
value 20 is assigned to variable b.

*a=b;
Value of b is assigned to pointer a.

a=&b;
Address of b is assigned to variable a.

3. Attempt any THREE of the following: 12 M

a) Describe the following terms 4M


(i) Keyword
(ii) Identifier
(iii) Variable
(iv) Constant

Page No: 5 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Ans Keywords: Each term 1
M
Keywords are special words in C programming which have their own predefined
meaning.

For Example: int, float, char, if, while, for, do.

Identifier: Identifiers are user-defined names of variables, functions and arrays. It


comprises of combination of letters and digits.

For Example :

int age1;

Here, age1 is an identifier of integer data type.

Variable: A variable is a name given to a storage area .Variable stores values. Each
variable in C has a specific type and size.

For Example :

int age1;

Here, age1 is variable of integer type.

Constant : Constants refer to fixed values that the program may not change

during its execution.

For Example :

const int a=30;

Here, a is an integer constant.

b) List the categories of functions and explain any one with example. 4M

Ans Different categories of function: List 2 M

1) Function with no arguments and no return value.

2) Function with arguments and no return value.

3) Function with no arguments and return value.

Page No: 6 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
4) Function with arguments and return value.

1) Function with no arguments and no return value: Explanation


of any one
This category of function cannot return any value back to the calling program and it does category
not accept any arguments also. It has to be declared as void.
2M

For example:

void add()

int a,b,c;

a=2;

b=3;

c=a+b;

printf(“%d”,c);

It should be called as add();

2) Function with arguments and no return value:

This category of function cannot return any value back to the calling program but it takes
arguments from calling program. It has to be declared as void. The number of arguments
should match in sequence, number and data type.

For example:

void add(int x,int y)

int z;

z=x+y;

Page No: 7 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
printf(“%d”,z);

It should be called as add(2,3); where x will take 2 and y will take 3

as their values.

3) Function with no arguments and return value:

This category of function can return a value back to the calling program but it does not
take arguments from calling program. It has to be declared with same data type as the
data type of return variable.

For example:

int add()

int a,b,c;

a=2;

b=3;

c=a+b;

return(c);

It should be called as int x = add(); where x will store value returned

by the function.

4) Function with arguments and return value:

This category of function can return a value back to the calling program but it also takes
arguments from calling program. It has to be declared with same data type as the data
type of return variable.

For example:

int add(int x, int y)

Page No: 8 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
{

int z;

z=x+y;

return(z);

It should be called as int s = add(2,3); where x will have 2 and y will have 3 as their
values and s will store value returned by the function.

c) State the use of printf( ) and scanf( ) with suitable example. 4M

Ans printf() : print() function is used to print the character, string, float, integer, octal and printf() use 1
hexadecimal values onto the output screen. M

scanf() : scanf() function is used to read character, string, numeric data from Scanf() use 1
M
Keyboard.

Example
Example:
2M
#include<stdio.h>

void main()

int i;

printf("Enter a number");

scanf("%d", &i);

printf("Entered number is: %d", i);

d) Give any four differences between call by value and call by reference. 4M

Ans Any four


Sr.No Call by value Call by reference valid
1 When function is called by passing When function is called by passing differences
values then it is call by value. address of variable then it is called as 1M each
call by reference.

Page No: 9 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
2 Copy of actual variable is created No copy is generated for actual
when function is called. variable rather address of actual
variable is passed.
3 In call by value, memory required is In call by reference, memory
more as copy of variable is created. required is less as there is no copy of
actual variables.
4 Example:- Example:-
Function call - Function call –
Swap ( x,y); Swap ( &x, &y );
Calling swap function by passing Calling swap function by
values. passing address.
5 Original (actual) parameters do not Actual parameters change as
change. function operates on value
Changes take place on the stored at the address.
copy of variable.

4. Attempt any THREE of the following: 12 M

a) Draw flowchart for finding largest number among three numbers. 4M

Ans (Can consider any other logically correct flowchart) Use of


correct
symbols

2M

Relevant
Logic 2M

Page No: 10 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

b) Write a program to display table of given number (Accept number from 4M


user).

Ans1. # include <stdio.h> Relevant


2. void main() logic 2 M
3. {
4. int num, i;
5. printf (" Enter a number to generate the table in C: "); Syntax 2 M
6. scanf (" %d", &num);
7. printf ("\n Table of %d", num);
8. for ( i = 1; i <= 10; i++)
{

printf ("\n %d * %d = %d", num, i, ( num* i) );

} }

Page No: 11 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
c) Write a program to sum all the even numbers between 1 to 100. 4M

Ans #include <stdio.h> Relevant


void main() logic 2 M
{
int i, sum=0; Syntax 2 M

for(i=2; i<=100; i=i+2)


{
sum =sum+ i;
}
printf("Sum of all even numbers from 1 to 100= %d", sum);

OR

#include <stdio.h>
void main()
{
int i, sum=0,rem;

for(i=1; i<=100; i=i++)


{
rem= i%2;
if (rem= =0)
{
sum =sum+ i;
}
}
printf("Sum of all even numbers from 1 to 100= %d", sum);
}
d) Develop a program to find the factorial of a number using recursion. 4M

Ans #include<stdio.h> Relevant


int factorial(int no) logic 2 M
{
if(no==1) Syntax 2 M
{
return(1);
}
else
{
return(no*factorial(no-1));
Page No: 12 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
}
void main()
{
int fact, no;
printf("\n Enter number");
scanf("%d", &no);
fact=factorial(no);
printf("\n Factorial number=%d", fact);
}
e) Write a program to accept ten numbers in an array. Sort array elements 4M
and display it.
Ans ( Can consider code of ascending OR descending sort of an array element) Relevant
logic 2 M

#include<stdio.h>
int main()
{ Syntax 2 M
int element[10],i,j,temp;
printf("enter 10 integer numbers:");
for(i=0;i<10;i++)
{
scanf("%d",&element[i]);
}
for(i=0;i<10-1;i++)
{
for(j=i+1;j<10;j++)
{
if(element[i]>element[j])
{
temp=element[i]; //swapping element[i] with element[j]
element[i]=element[j];
element[j]=temp;
}
}
}
printf("Elements are now in ascending order:");
for(i=0;i<10;i++)
{
printf("%d\n",element[i]);
}
return 0; }

Page No: 13 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

5. Attempt any TWO of the following: 12 M

a) Write a program to print Fibonacci series starting from 0 and l. 6M

Ans1. #include<stdio.h> Logic: 3 M


2. int main()
Syntax: 3 M
3. {
4. int n1=0,n2=1,n3,i,number;
5. printf("Enter the number of elements:");
6. scanf("%d",&number);
7. printf("\n%d %d",n1,n2); //printing 0 and 1
8. for(i=2;i<number;++i)
9. {
n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3;
}
return 0;
}

Output:
Enter the number of elements:15
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

b) Write a program for addition of 3 x 3 matrices. 6M

Ans #include<stdio.h> Any relevant


logic : 2 M
#include<conio.h>
Declaration
int main() and
initialization
{
of matrix: 2
int matA[3][3],matB[3][3],matC[3][3]; M

int r,c,k; Syntax : 2 M

for(r=0; r<3; r++)


{
for(c=0; c<3; c++)

Page No: 14 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
{
printf("Enter first matrix : ");
scanf("%d", &matA[r][c]);
}
}
for(r=0; r<3; r++)
{
for(c=0; c<3; c++)
{
printf("Enter second matrix : ");
scanf("%d", &matB[r][c]);
}
}
for(r=0; r<3; r++)
{
for(c=0; c<3; c++)
{
matC[r][c]=0;
for(k=0; k<3;k++)
matC[r][c] = matA[r][c] + matB[r][c];
}
}
printf("\n New addition matrix : \n");
for(r=0; r<3; r++)
{
for(c=0; c<3; c++)
printf(" %d",matC[r][c]);
printf("\n");

Page No: 15 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
getch();
return 0;
}

Output:
Enter first matrix :
123
456
789
Enter second matrix :
217
463
811

New addition matrix :


3 3 10
8 11 9
15 9 10

c) Write a program to compute the sum of all elements stored in an array using 6M
pointers.

Ans #include <stdio.h> Any relevant


logic : 2 M
void main()
Declaration
{ and
initialization
int arr1[10];
of Pointers:
int i,n, sum = 0; 2M

int *pt; Syntax : 2 M

printf("\n\n Pointer : Sum of all elements in an array :\n");


printf("------------------------------------------------\n");

Page No: 16 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

printf(" Input the number of elements to store in the array : ");


scanf("%d",&n);

printf(" Input %d number of elements in the array : \n",n);


for(i=0;i<n;i++)
{
printf(" element - %d : ",i+1);
scanf("%d",&arr1[i]);
pt = arr1; // pt store the base address of array arr1

for (i = 0; i < n; i++) {


sum = sum + *pt;
pt++;
}

printf(" The sum of array is : %d\n\n", sum);


}

Output:
Pointer : Sum of all elements in an array :
------------------------------------------------
Input the number of elements to store in the array : 5
Input 5 number of elements in the array :
element - 1 : 2
element - 2 : 3
element - 3 : 4
element - 4 : 5

Page No: 17 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
element - 5 : 6
The sum of array is : 20

6. Attempt any TWO of the following: 12 M

a) Write a program using structure to display information of employee which 6M


consist of employee id, name, age and salary.

Ans #include <stdio.h> Any relevant


logic : 2 M
Declaration
/*structure declaration*/ and
initialization
struct employee{
of structure:
int empId; 2M

char name[30]; Syntax : 2 M

float age;
float salary;
};

int main()
{
/*declare structure variable*/
struct employee emp;

/*read employee details*/


printf("\nEnter details :\n");
printf("ID ?:"); scanf("%d",&emp.empId);
printf("Name ?:"); gets(emp.name);
printf("Age ?:"); scanf("%f",&emp.age);
printf("Salary ?:"); scanf("%f",&emp.salary);

Page No: 18 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
/*print employee details*/
printf("\nEntered detail is:");
printf("Id: %d" ,emp.empId);
printf("Name: %s" ,emp.name);
printf("Age: %f" ,emp.age);

printf("Salary: %f\n",emp.salary);
return 0;
}

Output:
Enter details :
ID ?:1120
Name ?:Mike
Age?: 25
Salary ?:76543

Entered detail is:


Id: 1120
Name: Mike
Age: 25.000000
Salary: 76543.000000

b) Write a program to demonstrate use of strcmp( ), strcpy( ), strlen( ), strcat( ). 6M

Ans #include <stdio.h> Inclusion of


string.h -1 M
#include <string.h>
Program
#include <conio.h> logic : 1 M
int main() Syntax of
each
{
function (1

Page No: 19 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
char str1[10]="Hello"; M each) : 4
M
int l = strlen(str1);
printf("Length of the string = %d",l);
char str2[10]="World";
char str3[10];
strcat(str1,str2);
printf("\n %s",str1);
if(strcmp(str1,str2)==0)
{
printf("\n They are equal");
}
else
{
printf("\n They are not equal");

}
strcpy(str3,str1);
printf("\n %s",str3);
getch();

return 0;
}

Output:
Length of the string = 5
HelloWorld
They are not equal
HelloWorld

Page No: 20 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
c) Write a program to perform arithmetic operations on pointer. 6M

Ans #include<stdio.h> Logic:2 M


int main() Syntax of
pointer on
{ arithmetic
operation
int no1,no2;
:4M
int *ptr1,*ptr2;
int sum,sub,mult;
float div;
printf("Enter number1:\n");
scanf("%d",&no1);
printf("Enter number2:\n");
scanf("%d",&no2);

ptr1=&no1;//ptr1 stores address of no1


ptr2=&no2;//ptr2 stores address of no2

sum=(*ptr1) + (*ptr2);
sub=(*ptr1) - (*ptr2);
mult=(*ptr1) * (*ptr2);
div=(*ptr1) / (*ptr2);

printf("sum= %d\n",sum);
printf("subtraction= %d\n",sub);
printf("Multiplication= %d\n",mult);
printf("Division= %f\n",div);

return 0;
}

Page No: 21 | 22
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Output:
Enter number1:
20
Enter number2:
10
Sum=30
Subtraction =10
Multiplication = 200
Division = 2.000000

Page No: 22 | 22
22226
12223
3 Hours / 70 Marks Seat No.

Instructions – (1) All Questions are Compulsory.


(2) Answer each next main Question on a new page.
(3) Illustrate your answers with neat sketches wherever
necessary.
(4) Figures to the right indicate full marks.
(5) Assume suitable data, if necessary.
(6) Use of Non-programmable Electronic Pocket
Calculator is permissible.
(7) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.
Marks

1. Attempt any FIVE of the following: 10


a) Define the terms :
i) Flow chart
ii) Algorithm
b) State any four data types used in ‘C’.
c) List logical operators in ‘C’.
d) Define structure. Give one example of structure declaration.
e) State any two advantages of function.
f) Write the meaning of ‘&’ and * with respect to pointer.
g) Draw any two symbols used to construct flow chart. Also state
their use.

P.T.O.
22226 [2]
Marks
2. Attempt any THREE of the following: 12
a) Explain any four guidelines for preparation of flowchart.
b) Differentiate between while loop and do while loop.
c) Explain declaration and initialization of one dimensional array
using example.
d) Write output for following programming code:
#include<stdio.h>
#include<conio.h>
void main ( )
{
int x, y, a, b, *P1, *P2 ;
x = 10 ;
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) ;
}

3. Attempt any THREE of the following: 12


a) Explain data type conversion with example.
b) Explain any two string handling functions with syntax and
example.
c) Describe scanf() function with its syntax and example.
d) Describe how recursive function is used in calculating factorial
of a number.
22226 [3]
Marks
4. Attempt any THREE of the following: 12
a) Write an algorithm and draw a flowchart to find largest
number from three numbers.
b) Write a program to convert temperature in Fahrenheit degrees
to Centigrade degrees.
c) Write a C program to print following pattern using loop
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
d) Write a program to declare an array of 5 elements and
display sum of all array elements.
e) Write a C program using function to find area of circle.

5. Attempt any TWO of the following: 12


a) Write a C program with comments to reverse the digit of
integer number. For example the number 12345 should be
displayed as 54321.
b) Write a program to add two 3 × 3 matrices. Display the
addition.
c) Write a program to find largest number from an array using
pointer.

6. Attempt any TWO of the following: 12


a) Write a C program to declare structure employee having data
member name, age, designation and salary. Accept and display
information of 1 employee.
b) Write a program to find factorial of a number using recursion.
c) Write a C program using pointer to read an array of
characters and print them in reverse order.
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
22226
22223
3 Hours / 70 Marks Seat No.

Instructions – (1) All Questions are Compulsory.


(2) Answer each next main Question on a new page.
(3) Illustrate your answers with neat sketches wherever
necessary.
(4) Figures to the right indicate full marks.
(5) Assume suitable data, if necessary.
(6) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.
Marks

1. Attempt any FIVE of the following: 10


a) List the symbols used in flowchart. (any four)
b) Give the use of printf(  ).
c) Give the syntax of for loop.
d) Define array.
e) List any two string handling function.
f) Explain pointer with example.
g) Define algorithm.

P.T.O.
22226 [2]
Marks
2. Attempt any THREE of the following: 12
a) Write a ‘C’ program to find greatest number among three
numbers.
b) Explain Go-to statement with example.
c) Write ‘C’ program to add two distances given in kilometer
using structure.
d) Write a program to calculate sum of all elements stored in
given array using pointers.

3. Attempt any THREE of the following: 12


a) Explain use of comment in C language.
b) Explain any two math function with syntax and give example
of each.
c) Describe use of header files in C language.
d) Explain call by value with an example.

4. Attempt any THREE of the following: 12


a) Write a ‘C’ program to determine whether a given number is
prime or not and also draw flowchart for this program.
b) Explain formatted input-output function with example in C.
c) Explain do-while loop in C with proper example.
d) Write a ‘C’ program for multiplication of two 3 × 3 matrices.
e) Write a ‘C’ program to generate Fibonacci series for a given
number using recursion.
22226 [3]
Marks
5. Attempt any TWO of the following: 12
a) Write a ‘C’ program to print following pattern
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
b) Explain how to initialize and define structure in ‘C’
programming.
c) Develop a ‘C’ program to find sum of all elements stored in
given array using pointers.

6. Attempt any TWO of the following: 12


a) Write a ‘C’ program to find the largest and smallest number
in a given array.
b) Write a ‘C’ program to find factorial of a number using
recursion.
c) Write a ‘C’ program to demonstrate access structure members
using pointer.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

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: 10M
a) List the symbols used in flowchart (any four) 2M
Any four
Ans. symbols
1/2M each

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

b) Give the use of printf() 2M


Ans. printf statement is used to display output. Correct use
2M
c) Give the syntax of for loop. 2M
Ans. for (initialization; condition; increment/decrement) Correct
{ syntax 2M
Statement / body of loop;
}

d) Define array 2M
Ans. Array is a collection of similar type of data items / elements. Correct
definition
2M
e) List any two string handling functions 2M
Ans. 1. strlen() Any two
2. strcmp() functions
1M each
3. strcat()
4. strcpy()
5. strrev()
f) Explain pointer with example 2M
Ans. Pointer is a variable that stores address of another variable of similar Relevant
data type. explanatio
n 1M
OR Example
Pointer is used to refer to another variable. 1M

Example :
int a,*ptr;
a=5;
ptr=&a;

g) Define algorithm 2M
Ans. Algorithm is a stepwise procedure to perform a specific task. Correct
OR definition
2M
Algorithm is a set of steps performed in sequence to achieve desired
output.

2. Attempt any THREE of the following: 12M


a) Write a ‘C’ program to find greatest number among three 4M
numbers.

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

Ans. #include <stdio.h>


#include<conio.h> Input -1M,
logic for
void main() compariso
{ n-2M,
int no1,no2,no3; display
printf("Enter no1,no2,no3"); greatest
scanf("%d%d%d",&no1,&no2,&no3); number-
1M
if(no1>no2 && no1>no3)
printf("no1 is greatest");
else if(no2>no1 && no2>no3)
printf("no2 is greatest");
else
printf("no3 is greatest");
getch();
}

b) Explain Go-to statement with example. 4M


Ans. goto statement is used to pass the control of program execution from
one place to another place in a program. It requires a label to identify Correct
explanatio
a place where control will transfer after executing goto statement. A n-2M,
label is a variable name followed by colon.
Syntax:
Forward jump backward jump
goto label: label: Example-
2M
statements; statements;
label:
statements; goto label;

In forward jump goto statement In backward jump goto


skip some statements and jumps to statement jumps
a place marked with label. backward to find a place
marked with a label.

Example :
void main()
{
int a;
a=5;
if(a>0)

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

goto l1;
else
goto l2;
l1:
printf(“a is positive”);
l2:
getch();
}
In the above example, variable a is greater than 0 so program
execution control will pass to label l1 and will display a message as „a
is positive‟

Note : Any one shall be considered forward jump or backward jump


c) Write C program to add two distances given in kilometer using 4M
structure.
Ans. #include <stdio.h>
Structure
#include<conio.h> declaration
-1M,
struct distance
{ input
int kilometer; distance-
1M,
};
void main() addition -
{ 1M,
int sum;
struct distance d1,d2; display
addition-
printf("Enter distance for d1:"); 1M
scanf("%d",&d1.kilometer);
printf("Enter distance for d2:");
scanf("%d",&d2.kilometer);
sum=d1.kilometer+d2.kilometer;
printf("addition of two distance = %d",sum);
getch();
}
d) Write a program to calculate sum of all elements stored in given 4M
array using pointers.
Ans. #include <stdio.h> Input
#include<conio.h> array-1M,
void main()

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

{
int a[5]={1,2,3,4,5},*ptr,i,sum=0;
logic for
ptr=&a[0]; sum using
for(i=0;i<5;i++) pointer-
{ 2M,
sum=sum+*ptr;
ptr++; display
sum-1M
}
printf("Sum of array elements = %d",sum);
getch();
}

3. Attempt any THREE of the following: 12M


a) Explain use of comment in C Language. 4M
Ans. Comments can be used to explain code, and to make it more
readable. It can also be used to prevent execution when testing Correct
explanatio
alternative code. n 4M
Types of comments:
1. Single line
2. Multi-line

1. Single-line comment
It starts with two forward slashes (//).
Any text between // and the end of the line is ignored by the
compiler. It is not executed by the compiler.

Example:
// This is a comment
printf("Hello World!");

2. Multi line comment


Multi-line comments start with /* and ends with */.
Any text between /* and */ will be ignored by the compiler.

Example:
/* The code below will print the words Hello World!
to the screen, and it is amazing */
printf("Hello World!");

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

b) Explain any two math function with syntax and give example of 4M
each.
Ans. Math Functions in C: Any 2
math
1. sqrt() functions
sqrt() is used to find square root of a number. with
Syntax: correct
sqrt(no); syntax &
example
Example:
2M each
printf("%f", sqrt(16));

2. ceil()
ceil() function rounds a number upwards to its nearest integer.
Syntax:
ceil(no);
Example:
printf("%f", ceil(1.4));

3. floor()
floor() method rounds a number downwards to its nearest integer, and
returns the result.
Syntax:
floor(no);
Example:
printf("%f", floor(1.4));

4. pow()
pow() function returns the value of x to the power of y (xy).
Syntax:
pow(x,y);
Example:
printf("%f", pow(4, 3));

5. abs()
abs() function returns absolute value of a number.
Syntax:
abs(n);
Example:
printf(“%d”,abs(5));

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

6. sin()
sin() function returns sine value of an angle.
Syntax:
sin(x);
Example:
printf(“%f”,sin(60));
7. cos()
cos() function returns cosine of an angle.
Syntax:
cos(x);
Example:
printf(“%f”,cos(90));

8. tan()
tan() function returns tangent of an angle.
Syntax:
tan(x);
Example:
printf(“%f”,tan(30));

c) Describe use of header files in C language. 4M


Ans. 1. A header file is a source file that has the .h extension.
Correct
2. Header files contain the function prototypes or function
explanatio
declaration, whereas the source code contains the constants, n 4M
macros, system-wide global variables.
3. To define a function, include that header file in which function is
declared.
4. There are two types of header files defined in a program:
 System defined header file: The header file which is predefined
is known as a system defined header file.
 User-defined header file: The header file which is defined by the
user is known as a user-defined header file.
5. Both the user-defined and system-defined header file can be
included in a program with the help of using pre-processing
directive (#).
6. These pre-processor directives are used to instruct the compiler to
process these files before compilation.

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

Syntax:
#include<file>
Example:
#include<stdio.h>

d) Explain call by value with an example. 4M


Ans. Call by value:
1. In call by value method, the value of the actual parameters is copied Correct
explanatio
into the formal parameters. In other words, we can say that the value n 2M
of the variable is used in the function call in the call by value method.
2. In call by value method, we cannot modify the value of the actual
Correct
parameter by the formal parameter. example
3. In call by value, different memory is allocated for actual and formal 2M
parameters since the value of the actual parameter is copied into the
formal parameter.
4. The actual parameter is the argument which is used in the function call
whereas formal parameter is the argument which is used in the
function definition.
Example:
void swap(int x, int y);
void main ()
{
int a = 100;
int b = 200;
printf("Before swap, value of a : %d\n", a );
printf("Before swap, value of b : %d\n", b );
swap(a, b);
printf("After swap, value of a : %d\n", a );
printf("After swap, value of b : %d\n", b );
}
void swap(int x, int y)
{
int temp;
temp = x;
x = y;
y = temp;
}

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

4. Attempt any THREE of the following: 12M


a) Write a C program to determine whether a given number is 4M
prime or not and also draw flowchart for this program.
Ans. Program code:
Program
#include<stdio.h> with
#include<conio.h> correct
void main() logic and
{ syntax 2M,
int num, flag = 0, i;
clrscr(); Flowchart
printf("Enter the number"); with
scanf("%d",&num); correct
for(i = 2;i<num;i++) notations
{ 2M
flag = 0;
if(num%i==0)
{
flag=0;
break;
}
else
{
flag =1;
}
}
if(flag==1)
{
printf("The number is prime");
}
else
{
printf("The number is not prime");
}
getch();
}

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

Flowchart:

b) Explain formatted input-output function with example in C 4M


Ans. Formatted input:
When the input data is arranged in a specific format, it is
Explanatio
calledformatted input. n of
scanf function is used for this purpose in C. formatted
General syntax: input with
scanf(“control string”, arg1, arg2..); Example
control string here refers to the format of the input data. It includesthe 2M
conversion character %, a data type character and an optionalnumber
that specifies the field width. It also may contain new linecharacter or
tab.
arg1, arg2 refers to the address of memory locations where the
datashould be stored.
Example:
scanf(“%d”,&num1);

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

Formatted output: Explanatio


printf is used for formatted output to standard output depending on n of
formatted
theformat specification. Format specifier, along with the data to be output with
outputis the parameters to the function. The different format Example
specifiers usedare: 2M
%d-int values
%f-float values
%c-for char values
%s- for string
General syntax:
printf(“control string”,data1,data2..)
control string indicates how many arguments follow and their
datatypes.
data1, data2 are the variables whose data are formatted and
printedaccording to the specifications of the control string.
Example:
printf(“%d %d”,no1,no2);

c) Explain do while loop in C with proper example. 4M


Ans. do while loop is useful for things that want to loop at least once.
Syntax: Correct
explanatio
do n 2M
{
body of do while; Correct
} (condition); Example
2M
 The condition is tested at the end of the block instead of the
beginning, so the block will beexecuted at least once.
 If the condition is true, we jump back to the beginning of the
block and execute it again.
 dowhile loop is almost the same as a while loop except that the
loop body is guaranteed toexecute at least once.
Example:
main( )
{
inti = 0;

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

do
{
printf(“HELLO”);
}while (i!=0);
}
OUTPUT:
HELLO
Even though the condition is false the HELLO is printed once.

d) Write a ‘C’ program for multiplication of two 3 x 3 matrices. 4M


Ans. #include<stdio.h>
#include<conio.h>
Declaratio
int main() n 1M,
{ Input of
int mat1[3][3], mat2[3][3], mat3[3][3], sum=0, i, j, k; two
printf("Enter first 3*3 matrix element: "); matrices
for(i=0; i<3; i++) 1M,
Multiplicat
{ ion 1M,
for(j=0; j<3; j++) Display of
scanf("%d", &mat1[i][j]); resultant
} matrix 1M
printf("Enter second 3*3 matrix element: ");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
scanf("%d", &mat2[i][j]);
}
printf("\nMultiplying two matrices...");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
sum=0;
for(k=0; k<3; k++)
sum = sum + mat1[i][k] * mat2[k][j];
mat3[i][j] = sum;
}
}

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

printf("\nMultiplication result of the two given Matrix is: \n");


for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
printf("%d\t", mat3[i][j]);
printf("\n");
}
getch();
return 0;
}

e) Write a ‘C’ program to generate Fibonacci series for a given 4M


number using recursion.
Ans. #include<stdio.h>
#include<conio.h> Program
int Fibonacci(int); with
int main() correct
{ logic and
intn,i=0,c; syntax 4M
clrscr();
printf("\nEnter n:");
scanf("%d",&n);
printf("Fibonacci series\n");
for(c=1;c<=n;c++)
{
printf("%d\n",Fibonacci(i));
i++;
}
getch();;
}
int Fibonacci(int n)
{
if(n==0)
return 0;
else if(n==1)
return 1;
else
return(Fibonacci(n-1)+Fibonacci(n-2));
}

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

5. Attempt any TWO of the following: 12M


a) Write a ‘C program to print following pattern 6M
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Ans. #include <stdio.h>
#include<conio.h> Correct
void main() logic 3M
{ Correct
inti, j; syntax 3M

for (i = 5; i>= 1;i--) {


for (j = 1; j <= i; j++) {
printf("%d ", j);
}
printf("\n");
}
}
b) Explain how to initialize and define structure in ‘C 6M
programming.
Ans. Structure is a user defined data type. It is a collection of different Explanatio
n of
types combined together to create a new type. Definition
Defining structure: 3M
struct keyword can be used to declare a structure.
Syntax:
struct<name of structure>
{
//structure members

} variables;

Eg :
struct car
{
char name[100];
int price;
} car1;

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

Initializing structure:
a) Initialization the structure members directly like below :
struct car car1 ={"xyz", 987432}; Explanatio
b) To initialize or access a structure, dot . operator can be used as n of
struct car car1; Initializing
3M
car1.name=”xyz”;
car1.price=987432;

c) Develop a ‘C program to find sum of all elements stored in given 6M


array using pointers.
Ans. #include <stdio.h> Correct
#include<conio.h> logic 3M

Correct
void main() syntax 3M
{
inti, sum = 0;
int a[5]={1,2,3,4,5};
int *ptr;
ptr=a;
printf("Elements of the List \n");
for (i = 0; i< 5; i++)
{
printf("%d ", a[i]);
}
/* Compute the sum of all elements in the given array using
pointer */
for (i = 0; i< 5; i++)
{
sum = sum + *(ptr++);
}
printf("\nSum of all elements in array = %d\n", sum);
}
6. Attempt any TWO of the following 12M
a) Write a ‘C’ program to find the largest and smallest number in a 6M
given array.
Ans. #include<stdio.h>

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

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

int a[50],i,n,large,small; Correct


printf(“\nEnter the number of elements : “); logic 3M
scanf(“%d”,&n);
Correct
printf(“\nInput the array elements : “); syntax 3M
for(i=0;i<n;++i)
scanf(“%d”,&a[i]);

large=small=a[0];

for(i=1;i<n;++i)
{
if(a[i]>large)
large=a[i];

if(a[i]<small)
small=a[i];
}

printf(“\nThe smallest element is %d\n”,small);


printf(“\nThe largest element is %d\n”,large);
}

b) Write a ‘C’ program to find factorial of a number using 6M


recursion
Ans. #include<stdio.h> Correct
#include<conio.h> logic using
recursion
long factorial(int n) 3M
{
if (n == 0)
return 1;
else Correct
syntax
return(n * factorial(n-1)); 3M
}

void main()

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

SUMMER – 2023 EXAMINATION


MODEL ANSWER-Only for the Use of RAC Assessors

Subject: Programming in C Subject Code: 22226

{
int number;
long fact;
printf("Enter a number: ");
scanf("%d", &number);

fact = factorial(number);
printf("Factorial of %d is %ld\n", number, fact);
}
c) Write a ‘C’ program to demonstrate access structure members 6M
using pointers.
Ans. #include<stdio.h>\
#include<conio.h> Correct
struct student logic 3M
{ Correct
char *name; syntax 3M
int age;
float per;
};
void main()
{
struct student o={"XYZ",25,75.5};
struct student *ptr=&o;

printf("\nName : %s",(*ptr).name);
printf("\nAge : %d",ptr->age);
printf("\nPercent : %f",ptr->per);
}
Note: Any other program demonstrating access structure member
using pointers shall be considered

Page 17 / 17
22226
23124
3 Hours / 70 Marks Seat No.

Instructions – (1) All Questions are Compulsory.


(2) Illustrate your answers with neat sketches wherever
necessary.
(3) Figures to the right indicate full marks.
(4) Assume suitable data, if necessary.
(5) Mobile Phone, Pager and any other Electronic
Communication devices are not permissible in
Examination Hall.

Marks

1. Attempt any FIVE of the following: 10


a) Draw flowchart for checking whether given number is positive or
negative.
b) list any four keywords used in 'C'.
c) State any two decision making statements.
d) Define array and list its type.
e) List the categories of user defined function.
f) Define pointer. Write syntax for pointer declaration.
g) Draw and label any four symbols used in flowcharts.

P.T.O.
22226 [2]
Marks
2. Attempt any THREE of the following: 12
a) Draw flowchart for finding largest number among three numbers.
b) Write a program using switch statement to check whether entered
character is VOWEL or CONSONANT.
c) Differentiate between character array and integer array with respect
to size and initialization.
d) Explain pointer arithmetic operations with example.

3. Attempt any THREE of the following: 12


a) State the use of print f( ) and scan f ( ) with suitable example.
b) Explain any two string handling functions with syntax and example.
c) Describe the following terms:
i) Keyword
ii) Identifier
iii) Variable
iv) Constant
d) Write a program to find area of circle using user defined function.

4. Attempt any THREE of the following: 12


a) Write algorithm and draw flowchart to print even numbers from
1 to 50.
b) Explain increment and decrement operator with example.
c) Write a program to sum all the odd numbers between 1 to 20.
d) Illustrate initialization of one dimensional array with example.
e) Difference between call by value and call by reference.
22226 [3]
Marks
5. Attempt any TWO of the following: 12
a) Write a program to print fibonacci series starting from 0 and 1.
b) Write a program for addition of two 3 × 3 matrices.
c) Write a program to compute the sum of all elements stored in an
array using pointer.

6. Attempt any TWO of the following: 12


a) Write a program to declare structure employee having data
member name, age, city. Accept data for three employees and
display it.
b) Write a program to find factorial of a number using recursion.
c) Write a program to accept two numbers from user and perform
addition, subtraction, multiplication and division operations using
pointers.

You might also like