Model Answer Paper Summer 2018
Model Answer Paper Summer 2018
Model Answer Paper Summer 2018
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Page 1 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Syntax : Correct
strlen(string) Syntax
1M
(d) Write any two advantages of using function. 2M
Ans. Advantages of using function:
1) It can reduce length of the program. Any two
2) Easy to locate errors and debug. advanta
3) It implements top down approach. ges 1M
4) It provides reusability i.e. once a function is written, it can be each
used at many places, even in other programs.
(e) List two operators used with pointer. 2M
(Note: Any other relevant operators shall be considered) Any two
Ans. Operators used with pointers: operator
& - address of the variable s 1M
* - value at the address each
(f) State any four relational operators. 2M
Ans. Relational operators:
< Less than Any
> Greater than four
<= Less than equal to operator
>= Greater than equal to s-½M
== Equal to each
!= Not equal to
(g) Write syntax for scanf( ) function. Give one example. 2M
Ans. Syntax of scanf():
scanf("format specifier1 format specifier2,..format specifier n", & Syntax
variable1, &variable2… &variable n); 1M
Example:
Assuming a as an integer variable and b as a float variable, scanf() Example
can be used to input values into a and b as : 1M
scanf("%d %f",&a,&b);
(h) State the use of break statement. 2M
Ans. Use of break statement:
break statement is used to early exit from the loop/block. After Correct
exiting it transfers the control out of the loop/ block. use 2M
(i) Define the term character array. 2M
Ans. Character array is the one which can be used to store sequence of Definitio
characters inside it and can share a common name. n 2M
Page 2 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Page 3 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
1001
---- NOT
0110
-------
Page 4 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Bitwise XOR ^
Bitwise XOR ^, takes 2 bit patterns and perform XOR operation with
it.
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;
(b) Write a „C‟ program to calculate and display multiplication of 1 4M
to 7 numbers using for loop.
(E.g.: 1 * 2 * 3…. * 7 = 5040)
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h> Correct
#include<conio.h> logic 2M
main()
{
int i,p=1; Correct
clrscr(); syntax
for(i=1;i<=7;i++) 2M
{
p=p*i;
}
printf("Multiplication of numbers from 1 to 7 is = %d",p);
}
(c) Describe following functions with its syntax and example: 4M
(i) strcmp( ) (ii) strcat( )
Ans. (i) strcmp( ): Descript
It is a string function, which is used to compare the contents of two ion with
strings. Syntax
It returns 0 if both string are equal. Otherwise it returns the numerical of
difference between the ascii values of the first non matching pair of strcmp
Page 5 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
characters. ( ) 1M
Syntax:
strcmp(string1,string2);
Page 6 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
void main()
{
char str[10],*ptr;
int l=0; Correct
clrscr(); logic 2M
printf("\n Enter string:");
scanf("%s",&str);
ptr=str; Correct
while(*ptr!='\0') Syntax
{ 2M
l=l+1;
ptr=ptr+1;
}
printf("\n Length of string=%d",l);
getch();
}
(f) Describe the use of continue statement with example. 4M
Ans. Continue statement:
Continue statement is used to continue the loop with the next iteration Use of
after skipping any statement in between. The continue statement tells Continu
the compiler that “skip the following statements and continue with e
the next iteration”. Stateme
Syntax: nt 2M
continue;
Example:
for (int j=0; j<=8; j++)
{ Example
if (j==4) 2M
continue;
printf("%d ", j);
}
In the above example, Value 4 is not displayed because when j=4
continue statement skips printf() statement and continues with next
iteration of for.
Output: 0 1 2 3 5 6 7 8
3. Attempt any FOUR of the following: 16
(a) Describe with suitable example the concept of formatted output. 4M
(Note: Example can be a program or a code snippet)
Ans. Formatted output:
Page 7 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Example:
printf(“%d %d”,no1,no2); Example
In the above example %d specify format and no1, no2 are the 1M
variables whose value will be display on the screen.
(b) Write a „C‟ program to find gross salary of employee. Accept 4M
basic salary from user. If basic salary is less than 2000 then
calculate HRA = 11% and DA = 80% of basic salary. If basic
salary is equal or greater than 2000 then HRA = 600 and
calculate DA = 95% of basic salary. Display gross salary. (gross
salary = basic salary + HRA + DA)
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h>
#include<conio.h>
void main() Correct
{ syntax
float g_sal=0; 2M
float b_sal;
float hra;
float da;
clrscr() ; Correct
printf("Enter the basic salary"); logic 2M
scanf("%f",&b_sal);
if(b_sal < 2000)
{
Page 8 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
hra=b_sal*0.11;
da=b_sal*0.80;
g_sal=b_sal+hra+da;
}
else if(b_sal >=2000)
{
hra=600;
da=b_sal*0.95;
g_sal=b_sal+hra+da;
}
else
{
printf("Not valid");
}
printf("Gross salary is %f",g_sal);
getch();
}
(c) Describe „No argument with return value‟ category of function 4M
with example.
Ans. No argument with return value‟ category function does not accept any
argument but returns a value as a result of function execution. This Descript
function is declared and defined with data type of return value and ion 2M
function name in a prototype.
Syntax:
Return type function_name( )
{
Body of the function;
}
Example:
#include<stdio.h>
#include<conio.h>
int printNum(); Example
void main() 2M
{
int i = printNum();
printf("%d",i);
getch();
}
Page 9 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
int printNum()
{
int i = 10;
clrscr();
return i;
}
(d) Write a „C‟ program to find factorial of a number using 4M
recursion.
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h>
#include<conio.h>
int factorial(int num)
{
if( num==1)
{ Correct
return 1; syntax
} 2M
else
{
return(num*factorial(num-1)); Correct
} 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();
}
(e) With suitable example, describe any two operations on pointer. 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
Page 10 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Comparison operators
Pointers may be compared by using relational operators, such as ==,
<, and >. If p1 and p2 point to variables that are related to each other,
such as elements of the same array, then p1 and p2 can be compared
using the comparison operators.
(f) Write a „C‟ program to accept a string from user and copy it into 4M
another string. Display both the strings.
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h>
#include<conio.h>
void main()
{
int i; Correct
char str[20]; syntax
char dest[20]; 2M
Page 11 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
clrscr();
printf("Enter a string");
scanf("%s",str); Correct
for(i=0;str[i]!='\0';i++) logic 2M
{
dest[i]=str[i];
}
dest[i]='\0';
printf("The source string is %s",str);
printf("\nThe copied string is %s",dest);
getch();
}
OR
#include<stdio.h>
#include<conio.h>
void main()
{
char source[20];
char dest[20];
clrscr();
printf("enter the string");
scanf("%s",source);
strcpy(dest,source);
printf("Source string is %s",source);
printf("destination string is %s",dest);
getch();
}
4. Attempt any FOUR of the following: 16
(a) Describe conditional operator with syntax and example. 4M
Ans. Conditional operator:
Conditional operators return one value if condition is true and returns Descript
another value if condition is false. ion with
This operator is also called as ternary operator as it takes three syntax
arguments. 2M
Syntax: (Condition? true_value: false_value);
Example:
#include<stdio.h> Example
#include<conio.h> 2M
void main()
Page 12 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
{
int a,b,max;
clrscr();
printf("Enter the value of a & b:");
scanf("%d%d",&a,&b);
max=(a>b)?a:b;
printf(“%d is large”,max);
getch();
}
(b) Describe with example in which case do-while loop is most 4M
suitable than while loop.
Ans. Do-while is most suited when some statements of a program to be
executed at least once even if the condition is false. When while loop Descript
is used, if the condition is false then the statements will not be ion 1M
executed even once.
In menu driven programs do while loop is most suitable than while
loop as do loop displays menu options at least once without checking
any condition which is not possible with while loop.
Example:-
do Any
{ suitable
printf("Menu"); example
printf("\n1. Add \n2.Subtract"); with
printf("\n Enter your choice:"); descripti
scanf("%d",&ch); on 3M
switch(ch)
{
case 1:
...
...
}
printf("\n do you want to continue:(1/2)");
scanf("%d",&ch);
}while(ch==1);
In the above example, menu will be displayed without checking any
condition. Depending upon user's choice a case from switch will
execute. If user wish to continue then while loop takes the control
back to do statement.
Page 13 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Page 14 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Page 15 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Flowchart:
Correct
flowchar
t 2M
Page 16 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
skips the remaining part of current iteration of the loop and passes
control out of the block or loop. The break will exit only a single
loop.
Syntax: Relevant
break; descripti
Break statement is important in switch case statement to allow only on 4M
one case to execute from multiple cases. After executing statements
from a single case, control must be pass outside the switch so that
other cases cannot execute. If break statement is not given after any
case then all cases after that case will also execute.
Example:
switch(choice)
{
case 1:
printf(“welcome to case 1”);
break;
case 2:
printf(“welcome to case 2”);
case 3:
printf("welcome to case 3");
}
In the above example, if choice is 1 then first case will execute and
then break statement will transfer the control out of the block.
If choice is 2 then first case will be ignored and second case executes.
For second case break statement is not given so after executing
second case, third case will also execute.
(c) Write a 'C' program to read two matrices of 3 x 3. Calculate and 4M
display their addition.
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h>
#include<conio.h> Correct
void main() logic 2M
{
int a[3][3],b[3][3],c[3][3],i,j;
clrscr();
printf("Enter first matrix elements:\n");
for(i=0;i<3;i++) Correct
{ syntax
for(j=0;j<3;j++) 2M
Page 17 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
{
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];
}
}
printf("\n\nAddition of two matrices is:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",c[i][j]);
}
}
getch();
}
(d) Write a 'C' program to implement a menu for following : 4M
(i) To find whether the number is even or odd.
(ii) To find whether the number is positive or negative.
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h>
#include<conio.h>
void main()
{
int choice,no;
clrscr();
Page 18 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Static storage class: The value of the static variable persists until the
end of the program execution. A variable can be declared as a static
Page 19 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Example:
void func1()
{
static int x=0;
x= x+1;
printf(“x=%d”,x);
}
(f) State the meaning of each statement : 4M
int *ptr, no;
no = 5;
ptr = &no;
printf("%d %d", no,*ptr);
Ans. int *ptr,no; -> This statement declares a pointer variable 'ptr' and a
variable 'no' with data type as integer.
no=5; -> This statement initializes value 5 to variable „no‟ i.e. value Meanin
5 is stored in variable 'no' g of
each
ptr=&no; -> This statement initializes pointer variable 'ptr' with the step 1M
address of variable 'no' i.e it stores the address of variable 'no' in
pointer variable ptr.
Page 20 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
scanf("%f",&radius);
area=3.14*radius*radius;
printf("\n Area =%f",area);
getch();
}
(b) Write a 'C' program to print sum of digits in the number. 4M
(e.g. number = 2134, sum = 2 + l + 3 + 4 = l0)
(Note: Any other relevant logic shall be considered)
Ans. #include<stdio.h>
#include<conio.h> Correct
main() logic 2M
{
int no,q,r,sum=0;
clrscr();
printf("enter a number:");
scanf("%d",&no);
while(no!=0)
{ Correct
r=no%10; syntax
sum=sum+r; 2M
q=no/10;
no=q;
}
printf("sum of digits=%d",sum);
getch();
}
(c) Define array. With suitable example, describe how to declare and 4M
initialize one dimensional array.
Ans. Array: Definitio
An array is a collection of data elements of similar data type. The n 2M
values in an array are stored in continuous memory locations.
Page 21 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Example:-
int a[10] = {10, 20, 5, 3, 55, 45, 15, 7, 30, 52};
In the above example, an array variable a stores 10 integer values
inside it.
Page 22 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Page 23 / 24
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)
MODEL ANSWER
SUMMER – 2018 EXAMINATION
Subject: Programming in „C‟ Subject Code: 17212
Page 24 / 24