Sei sulla pagina 1di 6

(2½ Hours) [Total Marks: 75

N. B.: (1) All questions are compulsory.


(2) Make suitable assumptions wherever necessary and state the assumptions made.
(3) Answers to the same question must be written together.
(4) Numbers to the right indicate marks.
(5) Draw neat labeled diagrams wherever necessary.
(6) Use of Non-programmable calculators is allowed.

Solution Set(Reference Book - Programming with c By Byron Gottfried –Thrid Edition)

1. Attempt any three of the following:


a. List various techniques for the development of a program? Explain any one with
suitable example.(pg 1.10-1.6)

Program writing is a systematic process. It is not all about coding only. It requires a
certain methodology. Threre are three commonly used representation for the
development of a program as given below:
1.Algorithm
2.Pseudo-code
3. Flow chart
Any one of the above can be explained with example.

b. What is program development life cycle? Explain its various stages.

Page 1.12 - 1.7


Programmer for developing a program can not directly start any program or project.
Programmer has to understand whole program or project. He should analyse the
sequence and flow of the program. Following are the steps in program development
life cycle.
1. Understand the problem
2. plan the logic
3. code the program
4. use software
5. Program Testing
6. Put the program into production
7. Maintain the program

Explanation of all the above points should be given.

c. Discuss desirable program characteristics. (pg 1.21-1.12)


Explanation of following points should be given
Integrity
Clarity
Simplicity
Efficiency
Modularity
Generality

d. Define keywords and identifiers in C language? Also differentiate between keywords


and identifiers.

Page 2.3
e. What is a constant? List various constants in C. Explain any two in detail with suitable
examples.

Page 2.12 - 2.8


f. Assume that your version of c can recognize only first eight characters of an identifier
name, though identifier names may be arbitrarily long. Which of the following pairs
of identifier names are considered to be identical and which are distinct?
(i) Address , address (ii) name, names (iii) list1, list2 (iv) answer,
ANSWER (v) identifier_1, identifier_2

Ans. (i) Distinct (ii) Distinct (iii) Distinct (iv)Distinct (v) Identical

2. Attempt any three of the following: 15


a. What do you understand from hierarchy/precedence of operators? What is the
hierarchy of operators in c?
Ans. Chapter-3, Page 3.17 - 3.1
The order in which various operators are executed is known as hierarchy or
precedence of operators.
Order of execution of operators should be written in tabular form.

b. Explain the purpose and use of following operators with suitable examples
(i) == and =
(ii) Conditional operator (? :)

Ans. Chapter3, Page 3.13 – 3.4, Page 3.10 - 3.3 Page 3.16 – 3.5
c. A c program contains the following declarations and initial assignments
int i=8, j=5;
float x=0.005, y=-0.01;
Determine the value of each of the following expressions
(i) 2*(i/5)+(4*(j-3)) % (i+j-2)
(ii) (x>y)&&(i>0)||(j<5);

Ans. (i) 10 (ii) 1


d. Summarize the meaning of commonly used conversion characters within the control
string of a scanf() function.

Ans. Chapter 4, Page 4.4 - 4.4 (minimum four conversion characters should be
explained)

e. A c program contains the following variable declarations


float a=2.5, b=0.0005, c= 3000.;
Show the output from following printf statements
(i) printf(“%f %f %f”,a,b,c);
(ii) printf(“%3f %3f %3f”,a,b,c);
(iii) printf(“%8f %8f %8f”,a,b,c);
(iv) printf(“%8.4 f %8.4f %8.4f”,a,b,c);
(v) printf(“%e %e %e”,a,b,c);
Ans. (i)2.500000 0.000500 3000.000000
(ii)2.500000 0.000500 3000.000000
(iii) 2.500000 0.000500 3000.000000
(iv) __2.5000 0.0005 3000.0000
(v)2.500000e+000 5.000000e-004 3.000000e+003
f. Write an interactive c program to find roots of a quadratic equation ax2+bx+c=0 and
roots are given by -b±√(b2-4c)/2a.

//Find roots of a quadratic equation


#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,Root1,Root2,D,
printf(“\nEnter value of a:”);
scanf(“%f”,&a);
printf(“\nEnter value of b:”);
scanf(“%f”,&b);
printf(“/nEnter value of c:”);
scanf(“%f”,&c);
D=b*b-4*a*c;
If(D==0)
{
Root1=-b/(2*a);
Root2=Root1;
printf(“\nRoots are equal”);
printf(“\nRoot1=%f\tRoot2=%f”,Root1,Root2);
}
else if(D>0)
{
Root1=(-b+sqrt(b*b -4*a*c))/(2*a);
Root2=(-b-sqrt(b*b -4*a*c))/(2*a);
printf(“\nRoots are real and distinct:”);
printf(“\nRoot1=%f\tRoot2=%f”,Root1,Root2);
}
else
{
Printf(“\nRoots are imaginary”);
}

3. Attempt any three of the following: 15


a. What do you understand from control statements? Explain branching, selection and
looping in brief.

Ans. Chapter 6- Page 5.21


b. Differentiate between while and do while loop with suitable examples. When to use
which loop?
Ans. Chapter6, Page6.8 -6.3, 6.4
c. How many times following loops will be executed in the following codes
(i)for(i=10;i<=25;i++)
{………
……….
}
(ii)int i=0,n=10;
while(i<=n)
{
Sum+=i;
}
(iii)for(i=0,j=10;i<10;i++,j--)
{…………
…………}
(iv)for(i=100;i>70;i=i-2)
{……….
……….}
(v)int i=1,n=5;
while(i<=10)
{……….
If(i==n)
break;
i++;
}

Ans. (i) 16 (ii) infinite (iii) 10 (iv) 15 (v) 5


d. Predict the output of following c codes
(i)int i;
for(i=0;i<=2;i++)
{
switch(i)
{
case 1:printf(“%d”,i);
case 2:printf(“%d”,i);
default:printf(“%d”,i);
}
}

(ii)void swap(int, int);


void main()
{
int x=20,y=10;
swap(x,y);
printf(“%d, %d”,y,x);
}
void swap(int x, int y)
{
int temp;
temp=x;
x=y;
y=temp;
}
Ans. (i) 011122 (ii)10,20
e. What is a function? Explain the purpose of function prototype, function call and
function definition in a c program.
Ans. Chapter 7, page7.2,7.10
f. What is recursion? Write a recursive function to calculate factorial of a number.
Ans. Chapter 7, Page7.23

4. Attempt any three of the following: 15


a What do you understand from storage classes? List various storage classes? Explain
any two.
Ans. Chapter 8, Page 8.1
b What is the purpose of a static function in a multifile program? Explain with suitable
example.
Ans. Chapter 8, Page 8.5
c What are preprocessors in c language? List various preprocessors and explain #if-
#else-#endif preprocessor directive with suitable example.
Ans. Chapter 15, Page 15.20- 15.5
d What is a macro? Summarize the similarities and differences between macros and
functions.
Ans. Chapter 15, Page 15.11
e What is an array? How one dimensional arrays can be defined and accessed?
Ans. Chapter 9 Page 8.41
f Write a c program to find big number out of given n numbers stored in an array using
a function.

Ans.
//program to find big number using function
#include<stdio.h>
int Max(int n,int arr[]);
void main()
{
int n,a[100],big,i;
printf(“\nEnter number of elements in the array(not more than 100):”);
scanf(“%d”,n);
printf(“\n Enter %d elements of array:”);
for(i=1;i<=n;i++)
scanf(“%d”,&a[i]);
big=Max(n,a);
printf(“\nBig number=%d”,big);
}
int Max(int n1, int arr[])
{
int i,large=0;
for(i=1;i<=n1;i++)
{
if(arr[i]>large)
large=arr[i];
}
return large;
}

5. Attempt any three of the following: 15


a. A c program contains following statements
int i, j=25;
int pi,*pj=&j;
*pj=j+5;
i=*pj+5;
pi=pj;
*pi=i+j;
Suppose each integer quantity occupies 2 bytes of memory. If the value assigned to i
begins at address 1456 and value assigned to j begins at 1458 then
(i) What value is represented by &i and &j?
(ii) What value is represented by pj and *pj?
(iii) What value is assigned to i?
(iv) What is the value represented by pi?
(v) What value is represented by (pi+2)?
Ans. (i) 1456,1458
(ii)1458,65
(iii)35
(iv)1458
(v)1462

b. What is dynamic memory allocation? Explain the use of malloc function with
example.
Ans. Chapter 11, Page 11.18 – 11.5
c. Write a c program to perform addition and subtraction of two pointer variables.
Ans.
//Program to perform addition and subtraction of two pointer variables
#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,*ptr1,*ptr2,sum,sub;
printf(“\nEnter two integers to be added or subtracted:”);
scanf(“%d%d”,&n1,&n2);
ptr1=&n1;
ptr2=&n2;
sum=*ptr1+*ptr2;
sub=*ptr1-*ptr2;
printf(“\nSum=%d”,sum);
printf(“\nDifference=%d”,sub);
getch();
}
d. What is a structure? How does a structure differ from an array?
Ans. Chapter 12,Page 11.69 – 12.1
e. What is a union? Differentiate between structure and union?
Ans. Chapter 12, Page 12.55
f. (a) Define a structure of type hms containing three integer members, called hours,
minutes and second, respectively. Then define a union containing two
members, each a structure of type hms. Call the union members local and
home respectively. Declare a pointer variable called time that points to this
union.
(b) Define a union of type ans which contains an integer quantity called ians, a
floating point quantity called fans, a double precision quantity called dans.
Then define a structure with members a union of type ans called answer, a
single character called flag, integer quantities called a and b. Finally declare
two structure variables called x and Y
Ans. (a) struct nms
{
int hours;
int minute;
int second;
}
union
{
struct hms local;
struct hms home;
}*time;

(b) union ans


{ int ians;
float fans;
double dans;
};
struct
{
union ans answer;
char flag;
int a;
int b;
}x,y;

_____________________________

Potrebbero piacerti anche