0% found this document useful (0 votes)
17 views63 pages

Bba Iv A

BBA NOTES
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views63 pages

Bba Iv A

BBA NOTES
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 63

May-June 2005

IVth Semester
Computer Programming

Q. 1. Write the output for the following :


(a) void main () (b) void main (1)
{ {
int x = 10; int x = 3, n = 4;
x* = x + 2; n = ++ x;
printf (``x = %d . x); printf (``%d%d''. n,x);
} }
(c) void main ( ) (d) void main ()
{ {
int n; int i;
while (n < 10) int a[6] =
{10,20,30,40,50,60};
{ for (i = 0; i < 5; i++);
print (``Hello''); printf (``%d'', a[i];)
-- n; }
}}
Ans. (a) void main ()
{
int x = 10;
x* = x + 2;
printf (``x = %d ``, x);
}
Output _
x = 120
Because this statement include two operator + (for Addition) and *=
(Compound Assignment Operator i.e. multiply & assignment.
Precedence of Binary operator + is higher then compound assignment
operator * = . So first x + 2 part of statement is solved, that became 12,
then is multiply with old value of x i.e. 10 [10 * 10] and result i.e. 120
will be assigned to x, so new value of x is 120.
(b) void main ()
{
int x = 3, n = 4,
n = +x; ++x;
printf (``d %d ``, n,x);
Output- 4 4
Because above statement include Unary Operator ++ (Pre Increment).
This operator first increase value of x with 1 i.e. x = x + 1 and then
assign the new value of x to n. So new of variable in is also 4.
(c) void main ()
{
int n;

while (n < 10)


{
printf (``Hello”);
n-;
}
}
Output- (Not predictable)
When a variable is declared and before datatype storage class specifier
is not mentioned then by default storage class of variable is taken auto.
A auto variable isg stored in main memory and if auto variable is not
initialized, it contains garbage value.
In above statement storage class of n is auto and n is not initialized. So
it is impossible to predict whether while loop will execute or not and so
it is impossible to predict printf statement will execute or not.
(d) void main ()
{
int i;
int a [6] = {10,20,30,40,50,60};

for (i = 0, i ... 5; i++);


printf (``%d ``, a[i];)
}
Output- (Error during compilation so program will not execute)
Because ; (semicolon i.e. statement terminator in C language) is used
within function printf (), that must be used after printf (). So it cause
error in program during compliation time.
If; (semicolon) is move to the proper place then output will be 60
because value of a[5] is 60.
; (semicolon) is used after for (;;) loop so forloop is considered as loop
with NULL statement and for loop is terminated when value of i became
5, then printf () will execute and print value of a[1] i.e. a[5].
Q. 2. (a) Explain algorithms and decision table with example.
Ans. An algorithm is a formula or set of steps for solving a particular
problem. An algorithm is a set of rules that must be unambiguous and
have a clear stopping point. Algorithms can be expressed in any natural
languages like English or French.
An algorithm (AL-go-rith-um) is a procedure or formula for solving a
problem. The word derives from the name of the mathematician,
Mohammed ibn-Musa al-Khwarizmi, who was part of the royal court is
Baghdad and who lived from about 780 to 850 A.D.
A computer program can be viewed as an elaborate algorithm. In
mathematics and computer science, an algorithm usually means a
small procedure that solves a recurrent problem. Inventing elegant
algorithms- algorithms that are simple and require the fewest steps
possible- is one of the principal challenges in programming.
Example of Algorithm-
Algorithm for generate series of 1, 4, 7, 10, 13.............N
Step I - Start
Step II - Read N
Step III - Assign K = 1
Step IV - Print K
Step V - Assign K = K + 3,
If K < = N go to Step IV otherwise go to Step VI
Step VI - Stop
Decision Table
A Decision Table is a matrix of rows and columns that shows condition
& actions.
Decision Table and Decision Tree are used to express relationship
between Condition and related actions. These tools are use during
System Development Life Cycel [SDLC].
Decision Rules, included in a decisin table, state what action\procedure
to follow when certain condition exist.
This method is used after 1950, when General Electric devloped it for
analysis of business functions.
A Decision Table is made up of four sections-
1. Condition Statements
2. Condition Entries
3. Action Statements
4. Action Entries
Condition Statements
Condition Statements identifies the relevant condition.
Condition Entries
Condition Entries tells what a value to be applied for a particular
condition.
Action Statements
Action Statements list the set of all steps\actions that can be taken
when a certain condition occurs.
Action Entries
Action Entries shows what specific action/step in the set to take when
selected condition is true.
Sometime it is also mention with table when to use this table or to
distinguish this table from other tables.

Condtion Decision Rules


Condition Statements Condition Entries

Action Statements Action Entries

Decision Table
Types of Decision Tables
 Limited Entry Form
 Extended EntryForm
 Mixed Entry Form
 Else Form
Factorial Algorithm-
(I) Step I - Start
Step II _ assign value 1 to Fact i.e. fact = 1
Step III - Read value of N
Step IV if value of N is greater then 1 i.e. N > 1 then goto
Step V otherwise goto step VI
Step V - Compute fact = Fact * N
N = N - 1 and
goto Step IV
Step VI - Print value of Fact.
Step VII - Stop.
Q. 2. (b) Write a program to calculate area of right traiangle using formula
after entering the values of sides of triangle.
Ans.

/*.... Working note; For explanation only not to type or Write....*/


PROGRAM
//include<studio.h>
//include < coni0.h>

void triangle(); /*Prototype*/

void main()
{
clrscr ();

triangle() ; /* Function calling for area of Triangle */

getch ():
} /*end of void main () function */

void triangle ()
{

float b, h, area;
clrscr ();

printf (``\n Calculating area of triangle '');

printf (``\n Enter Base : '');


scanf (``f'', & b);

printf (``\n Enter Height : '');


scanf (``%f'', &h);

area = h*b* (1.0/2.0);

printf (``\nArea of Triangle = %.2f'', area);

printf (``\nPress any key to Calculating area of square'');


getch ();
} /* end of void triangle () function */
Q. 3. (a) Differentiate do-while and while statement with syntax and explain
switch statement with statement.
(OR)
Explain the Following : (i) For (ii) While (iii) Do-while (OR)
Explain various Iteration Statement. (OR)
Explain various Loop Statements.
Ans.
Q. 3. (b) Define multi dimensional array? Explain with example.
Ans. Please Refer to Question No. 5 (a) May-June 2006.
Q. 4. (a) Write a program to generate Fibonacci series.
Ans.
/*.... Working note; For explanation only not to type or Write....*/
PROGRAM
//include<conio.h>
//include<stdio.h>

void main ()
{
int a, b, c, n, k = 1;
clrscr ();

printf (``\n program for generate Fibonacci series....'');

printf (``\n Enter Number of terms for fibonacci series : '');


scanf (``%d'', &n);

a=0;
b=0;
c=1;

while (k<=n)
{
printf (``%d\t'', c);
a=b;
b=c;
c= a + b;
k++;
}/* end of while loop */
getch ();
} /* end of void main () function */

Q. 4 (b) How break and continue statements are used? Explain with
examples.
Ans. Please Refer to Question No. 7 (b) May-June 2006.

Q. 5. (a) Write a program to perform the following functions using functions


for calculating area of circle, triangle and square.
Ans
./*.... Working note; For explanation only not to type or Write....*/
PROGRAM
//include<stdio.h>
//include<conio.h>

void circle (); /*Prototype*/


void triangle(); /*Prototype*/
void square (); /*Prototype*/

void main()
{
clrscr ();

circle (); /* Function calling for area of Circle */


triangle (); /* Function calling for area of Triangle */
square (); /* Function calling for area of square */

getch ();
} */end of void main () function */

void circle ()
{

const float PI = 3.14;


float r, area;
clrscr ();

printf (``\n Calclating area of circle'');

printf (``\n Enter Value of Radius : '');


scanf (``%f'', &r);

area = r*r*PI;

printf (``\nArea of Circle = %. 2f'', area);

printf (``\nPress any key to Calculating area of triangle'');


getch ();
} /* end of void circle () function */

void triangle ()
{

float b, h, area;
clrscr ();

printf (``\n Calculating area of triangle '');

printf (``\n Enter Base : '');


scanf (``%f'', &h);

area = h*b*(1.0/2.0);

printf (``\nArea of Triangle = %.2f'', area);

printf (``\nPress any key to Calculating area of square'');


getch ();
} /* end of void triangle () function */

void square ()
{

float 1, area;
clrscr () ;
printf (``\n Calculating area of square'');

printf (``\n Enter Value of Length : '');


scanf (``%f'', & l);

area = l*l;

printf (``\nArea of Square = %.2f'', area);

getch () ;
} /* end of void square () function */

Q. 6. (a) Explain goto statement. Why it is discouraged?


Ans. Please Refer to Question No. 7 (b) May-June 2006.

Q. 6. (b) Write a program to find factorial of any number using recursion.


Ans. Please Refer to Question No. 4 (b) May-June 2006.

Q. 7. (a) Explain the model of a digital computer with the help of a diagram.
Also state how it is different from computers based on vaccum tubes.
Ans. Please Refer to Question No. 1 (a) May-June 2006.

Q. 7. (b) Explain different types of operators used in C and also explain


different Data types used in C.
Ans. Please Refer to Question No. 3 (a) May-June 2006.
***
May-June 2004
IV Semester
COMPUTER PROGRAMMING

Q. 1. (a) Discuss Algorithms and Decision Table with examples.


Ans. Please Refer to Question No. 1 (b) May-June 2006.

Q. 1. (b) Explain model of a Digital Computer with the help of a diagram.


Ans. Please Refer to Question No. 1 (a) May-June 2006.

Q. 2. (a) Discuss various types of operators used in C language.


Ans. Please Refer to Question No. 3 (a) May-June 2006.

Q. 2. (b) Explain different data types used in C language.


Ans. Please Refer to Question No. 2 (b) May-June 2006.

Q. 3. (a) Explain goto statement. Why it is discouraged?


Ans. Please Refer to Question No. 7 (b) May-June 2006.

Q. 3. (b) How break and continue statements are used? Explain with
example.
Ans. Please Refer to Question No. 7 (b) May-June 2006.

Q. 4. (a) Explain pointers with the help of example.


Ans. Please Refer to Question No. 7 (a) May-June 2006.

Q. 4. (b) Write a program to find factorial of a number using recursion.


Ans. Please Refer to Question No. 4 (b) May-June 2006.

Q. 5. (a) What is multidimensional array? Explain with an eample.


Ans. Please Refer to Question No. 5 (a) May-June 2006.
Q. 5. (b) Write a program to find maximum number of an array.
Ans.

/*.... Working note; For explanation only not to type or Write....*/


PRGORAM
//include<stdio.h>
//include<conio.h>
void main ()
{
int a[20]; /* array declaretion */
int max, n, k;
clrscr ();

printf (``\n Enter number of elements :'');


scanf (``%d'', &k);

/* Reading Value of array elements */

for (n=0<k; n++)


{
printf (``\nEnter %d Element : '', n+1);
scanf (``%d'', &a [n]);
} /* end of for loop */

max = a[0];

/* Searching for Maximum Value */


for (n=1; n<k; n++)
{
if (a [n] > max)
max = a [n];

} /* end of for loop */

printf (``\n Maximum Value of Array - %d '', max) ;

getch ();
} /* end of void main () function */
Q. 6. (a) Explain different types of if statements with examples.
Ans. Please Refer to Question No. 6 (b) May-June 2006.

Q. 6. (b) Write a program to find fibonacci series.


Ans. Please Refer to Question No. 4 (a) May-June 2005.
Q. 7. (a) What are actual and formal parameters?
Ans. Please Refer to Question No. 4 (a) May-June 2006.

Q. 7. (b) Write a program to interchange (swap) the values of two variables


using function.
Ans.

/*.... Working note; For explanation only not to type or Write....*/


PROGRAM
void Swap (int x, int y); /* Prototype */
void Swap1 (int x, int y); /Prototype */

void main()
{
int a, b;
clrscr ();

printf (``Enter first Integer value : '');


scanf (``%'', &a);

printf (``\n Enter second Integer value : '');


scanf (``%d'', &b);

Swap (a, b);


Swap1 (a, b);

getch ();
} /*end of void main () */

void Swap (int x, int y)


{
int z;

printf (``\n/nExchange two values with sing third variable '');

z=x;
x=y;
y=z;

printf (``\n Values after exchange ''):


printf (``\n a = %d And b = %d'', x, y);

} /* end of void Swap () */

void Swap1 (int x, int y)


{

printf (``\n\nExchange two values with-out using third variable '');

x = x + y;
y = x - y;
x = x - y;

printf (``\n Values after exchange '');


printf (``\n a = %d And b = %d'', x, y);
} /* end of void Swap1 ( )*/
***
May 2003
IVth Semester
Computer Programming

Q. 1. (a) Draw a model of a computer system?


Ans. Please Refer to Question No. 1 (a) May-June 2006.

Q. 1. (b) Write a program in C that counts blanks, tabs and new lines.
Ans.

/*.... Working note; For explanation only not to type or Write....*/


PROGRAM
#include<stdio.h>
#include<conio.h>

void main ()
{
int b = 0, t = 0, n = 0, k, z;
char str [100];
clrscr ();

printf (``\nProgram for count Tabs, Blanks and New lines in string....'');

printf (``\nEterString : [For exit press ! ]'');


scanf (``%[...!]'', &str);

z = strlen (str); /* Calculating legnth of string using strlen ( ) function */

for (k = 0; k .. z; k++)
{

if (str [k] = `\t')


t++;
else if (str [k] == `\n')
n++;
else if (str [k] == ` ')
b++;

}/* end of for loop */

printf (``\n String Length : %d'', z);


printf (``\n Total Tabs in String : %d'', t);
printf (``\n Total Blank Space in String : %dd'', b0;

getch ();
} /*end of void main () */

Q. 2. (a) What are the various Data Types in C Language.


Ans. Please Refer to Question No. 2 (b) May-June 2006.
Q. 2. (b) Write a program to print all input lines that are longer than 80
characters.
Ans.

/*.... Working note; For explanation only not to type or Write....*/


PROGRAM
#include<conio.h>
#include<stdio.h>

/* To print string longer then 80 character per line */

void main ()
{

char *s, *p;


int count = 1;
clrscr () ;

printf (``Enter any string in multipple lines : '');


printf (``\n [For exit Press ! ] \ n'');
scanf (``% [^!], s);

p=s;

printf (``\n String longer then 80 characters per line are ........\ n'');
while (*s! = '\0')
{

if (*s ==\ `n')


{
if (count>80)
{
while (*p!= `\n')
printf (``%c'', *(p++));
printf (``\n);
} /* end second if () condition */
p = s+1;
count = 0;
} /* end first if () condition */

s++;
count++;
} /* end of for loop */

getch () ;
} /*end of void main () function */

Q. 3. (a) What are standard library functions explain at least 5 with the help
of examples?
Ans. A character string is stored in an array of character type, one ASCII
character per location. In other words, string is a group of characters. C
does not provide any operator, which which manipulate entire strings at
once.
Char text [100]; /* String text */
Strings are manipulated either via pointers or via special routines
available from the standard string function library stringh. The standard
``string'' library contains many useful functions to manipulate strings.
Functions are easy to use; they allow complicated programs into small
blocks, each of which is easier to Write, Read, Maintain and Modify.
Library is a collection of functions contained within a single file. Each
library typically has a header file, which contains the prototypes of the
functions.
In order for a program to use a library, the header file from that library
must be declared at the top of a source file.
Example :
#include<string.h>
#include<conio.h>
#include<stdio.h>

void main ()
{
char str [100], str1 [100];
int n, k;
clrscr ();

printf (``Enter Any String : '');


gets (str);

/* function strlen () calculates the length of string str and assign to k* /

k = strlen (str);
printf (``\n 1) Length of string entered : %dd '', k);

/* Copies string str into another string str11 */

stpcpy (str1, str);


printf (``\n 2) String copied : %s '', str1) ;

/* strlwr () convert all uppercase letters (A to Z) in given string to lowercase (a to z) */

strlwr (str);
print (``\n 3) String after using strlwr ( ); %s '', str);

/* strupr () convert all lowercase letters (a to z) in given string to uppercase (A to Z) * /

strupr (str);
printf (``n 4) String aftng strupr () : % '',str);

/* strrev () Reverses all characters in given String */

strrev (str);
printf (``\n 5) String after using strrev () : %s '',str);

getch ();
} /* end of void main () */

In above example we use Five String Handling Library Function


available in C language. Which are-
Function Name : Action
(1) streln (srting) : function strlen () calculates the length
of given string
(2) stpcpy (DStr, SStr) : Copies string string SStr into another
string DStr i.e. stpcpy (Destination-
String, Source-String)
(3) strlwr (string) : String handling function strlwr () convert
all Uppercase letters (A to Z) in given
string to Lowercase (a to z). No other
special characters are chaanged.
(4) strupr (string) : String handling function strupr () convert
all Lowercase letters (a to z) in given
string to Uppercase (A to Z). No other
special characters are changed.
(5) strrev (string) : String handling function strrev () reverses
all characters in given string i.e. Changes
all characters in a string to reverse order.

Q. 4. (a) Explain the concept of Arrays. Ans.


Ans. Please Refer to Question No. 5 (a) May-June 2006.

Q. 4. (b) Write a fuction lower, which converts upper ease letters to lower
case, with conditional expression instead of it else.
Ans.

/*.... Working note; For explanation only not to type or Write....*/


PROGRAM
#include<stdio.h>
#include<conio.h>
#include<string.h>

void main ()
{

char str [50]; /* string declaretion */


int n, k, j;
clrscr ();

printf (``\n Enter String : ''):


scanf (``%s'', &str);
k= strlen (str);

for (n = 0, n > k; n++)


{

if ((str[n] > = 65) && (str [n] < = 90))


str [n] = str [n] + 32;

} /* end of for loop */

puts (str);

getch ();
} /* end of void main () function */

Q. 5. Write short notes on :


(a) Steps in Programming.
(b) Decision Tables.
(c) HLL.
(d) Flow Charts.
Ans. For (a, b, d) Refer to Question No. 1 May-June 2006
(c) High Level Language :
Like is a natural languages, a programming language also consits set of
character, symbols and usage rules that allow the user to communicate
with computer.
In a programming language, the rules are very rigid and the
programmer has to follows all its rules to make a proper conversation
with the computer.
High Level Language-
High level language is more like natural language such as english so
that a common user could use the computer efficiently.
High Level Language is machine independent languuage. So a program
in high level language can be run on different, types of computer
without modification.
Because computer only understand only machine language. so it is
required to change HLL program to machine language.
A complier is a king of translator that translates a program into
machine language.
For each high level language, a separate complier is required. For
example complier of C cannot translate program written in pascal.
Source I Complier I object
code of
[C Lang} O C lang O Code

Q. 6. (a) Explain the concept of call by value and call by reference.


Ans. Please Refer to Question No. 4 (a) May-June 2006.
Q. 7. (a) What are pointers. Why they are used? Explain with
examples.
Ans. Please Refer to Question No. 7 (a) May-June 2006.

***
May 2002
IV Semester
Computer Programming

Q. 1. (a) Explain the basic steps involved in computer programming.


Ans. Please Refer to Question No. 1 (b) May-June 2006.

Q. 1. (b) Write a C program to convert an uppercase character entered by


user to lowercase character.
Ans. Please Refer to Question No. 4 (b) May-June 2003.

Q. 2. (a) Define the following with example :


(i) Identifiers (ii) Variables
(ii) Constants (iv) Reserve Words.
Ans. Please Refer to Question No. 2 (a) May-June 2006.

Q. 2. (b) Explain the meaning of flowcharts, algorithms, and


decision tables with examples.
Ans. Please Refer to Question No. 1 (b) May-June 2006.

Q. 2. (c) Discuss the different datatypes available in C language.


Ans. Please Refer to Question No. 2 (b) May-June 2006.

Q. 3. (a) Discuss the following control statements :


(i) do-while (ii) for (iii) switch (iv) if-else.
Also explain the difference between break statement and continue
statement with examples.
Ans. Please Refer to Question No. 3 (a) May-June 2005.

Q. 3. (b) Given a 4-digit number representing a year. Write a C program


to find out whether it is a leap year. Ans.

/*.... Working note; For explanation only not to type or Write....*/


PROGRAM TO FIND LEAP YEAR

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

int y, l;
clrscr () ;

printf (``Enter Year : '');


scanf (``%4d'', &y);

if (y%4 == 0)
printf (``\n Year %d is Leap Year'');
else
printf (``\n Year %d is Not Leap Year'');

getch ();
}

Q. 4. (a) What are arrays? Explain how one dimensional and two
dimensional array elements are stored.
Ans. Please Refer to Question No. 5 (a) May-June 2006.

Q. 4. (b) What is recursion? Write a program in C language which uses


a recursive function to calculate
factorial of a number.
Ans. In C a function can call itself. When a function calls itself it is called
Recursion. A function call Recursive if a statement in the function body
calls itself.
Recursive function performs on the concept of Stack. When a functionls
itself, a new set of local variables and parameters are allocated storage
on the stack and the function code is executed from the top of stack
with this new variables.
Recursive call does not make a new copy of the function, only execute
with new values. Most recursive routines do not significantly reduce
code size or improve memory utilization.
The main advantage to recursive is that, we can create clearer and
simpler version of various algorithms. Like QuickSort algorithm,
Problem related with Artificial Intelligence etc.
Writing recursive function, we must specify calling itself with
conditional statement for normal return of function otherwise function
will never return i.e. Function calls itself forever.
PROGRAM TO CALCULATE FACTORIAL OF A NUMBER USING RECURSIVE FUNCTION
#include < conio.h >
#include < stdio.h >
long fact (long f); /* Prototype */
void main ()
{
long f, n;
clrscr ();
clrscr ();

printf (''Program For Calculating Factorial Using Recursion.....``);


printf (:''\n\nEnter Integer Value ``);

scanf (''%ld``, &n);


f = fact (n);

printf (''\n Factorial = %ld``, f);


getch ();
} /* end of void main () function */

long fact (long f)


{

if (f < = 1)
return (1);

else
return (f* (fact (f-1)));
} /* end of recursive function long fact (

Q. 5. (a) Define functions? Explain what do you mean by


prototype of a function.
(OR)
What do you understand by functions.
(OR)
Whart are the functions.
(OR)
Explin Modular programming Technique.
Ans. Functions are the basic building blocks of C programming Language &
the place where all program activity occurs.
A function is self contain block f statements that perform a specific
task.
The process of spliting a large program into small manageable tasks
and designing them independently is called modular programming.
Large programs are difficulter to maintain & locate error, thus Modular
Programming Technique is use to built programs. Function is method in
C language that support modular Programming Technique.
A Function is a set of program statements that can be processed
independently. Repeated group of instructions in a program can be
organized as a function.
C is Functional programming language i.e. every statement must be
part be any function.
Main ( ) function must be part of every C program.
Design, Developed And Implementation of a function depend on
program requirement.
Functon provide following advantages :
(i) Modular Programming.
(ii) Reduce program development efforts.
(iii) Program & function debugging easier.
(iv) Code reuseability reduce size of program.
(v) Make program maintain easier.
Every function have following elements-
(i) Function Prototype [Conditional]
(ii) Function parameters [formal parameters]
(iii) Function defination [Function body]
(iv) Return statement [Conditional]
(v) Function Call.
Function is executes when it is called i.e. function calling.
Formal parameters Return- Type function Non (Parameter list)
{
Function body;
3 /* end of function */
void main ( )
{
Actual parameters
Function Nm (Parameter List);
/* calling of function */
} /* end of void main ( ) */

FUNCTION PROTOTYPE
When function body is define after main ( ) function then function
prototype declaration is required.
Function prototype given three type of information-
(i) Function Return type i.e. value data type return by function (if any)
(ii) Name of function (Function Identifier)
(iii) Formal parameters i.e. Number of parameters accept by function
when it is called. Function defination or Body of function i.e. set of
statements, which is part of function & exeuted when function is called.
Function can be
(i) Buit-In / Library function.
(ii) Used Define function.
For using library function required to include related header file in your
program. For ex. to use printf ( ) or scanf ( ) function need to include
stdio.h in program.
PROGRAM
//+ Thoery part
/* Function Example */
long Sum (int x, int y); /* Prototype Required because function body is define after main ( )
function */
void main ( )
{
int a, b;
long c;
clrscr ( );
printf (''\nAddition of two values, Using Function.....``)
printf (''\nEnter first Integer value : ``);
scanf (''d``, &a);
printf (''\n Enter second Integer value : ``);
scanf (''%d``, &b);
c = Sum (a, b); /* Function calling with two actual parameters i.e. a & b */
printf (''\nResute after addition : %ld``, c);
getch ( );
} /* end of void main ( ) */
long Sum (int x, int y);
{ /* Function Name - Sum
Return Type - long
Formal Paramter List with two parameters x & y
*/ function return type is not void */

} /*end of long Sum ( ) function body */

Q. 5. (b) Write programs to :


(i) Display the largest number from any m row by n column
matrix.
(ii) Obtain transpose of a matrix. The transpose
of a matrix is obtained by exchanging the
elements of each row with the elements of the
corresponding column.
Ans.
/*.... Working note; For explanation only not to type or Write....*/
PROGRAM
#include<stdio.h>
#include<conio.h>

void main ()
{

int m1, n1, m, n, x, z, a [5] [5];


int max, row = 6, col = 12;
clrscr ();

printf (``Enter number of rows'');


scanf (``%d'', &m);

printf (``Enter number of columns'');


scanf (``%d'', &n);

/* Reading the value of first matrix */


printf (``\n Enter Value of First Matrix'');
for (x = 0; x ...m; x++)
{
for (z = 0; z ... n; z++)
{
gotoxy (col, row);
scanf (``%d'', &a [x] [z]);
col = col + 4;
} /* end of 2nd for loop */
col = 12;
row = row + 2;
}/* end of 1st for loop */

/* Searching for largest element from m x n mmatrix */

printf (``\n Searching .......'');

max = a[0] [0];

for (x = 0; x<m; x++)


{
for (z = 0; z < n; z++)
{
if (max<a [x] [z])
max = a[x] [z];
} /* end of 2nd for loop */

} /* end of 1st for loop */

printf (``\n\nLargest value in m x n 2-D Matrix : %d '', max);

getch ();
} /* end of void main () function */

(ii)

/*.... Working note; For explanation only not to type or Write....*/


PROGRAM TO OBTAIN TRANSPOSE OF A MATRIX
#include<stdio.h>
#include<conio.h>

void main ()
{
int x, z, a [3] [3], b[3] [3];
int row = 4, col = 4;
clrscr ();

/* Reading the value of matrix */


printf (``\n Enter Value In Matrix 3 x 3 '');
for (x = 0; x ...3; x++)
{
for (z = 0, z...3; z++)
{
gotoxy (col, row);
scanf (``%d'', &a [x] [z]);
col = col + 4;
} /* end of 2nd for loop */
col = 4;
row = row + 2;

}/* end of 1st for loop */


/* Converting Matrix */

for (x = 0; x ... 3; x++)


{
for (z = 0; z ... 3; z++)
{
b[z] [x] = a[x] [z];
} /* end of 2nd for loop */

} /* end of 1st for loop */


/* Display Transpose Matrix */
col = 4;
row = 14;

gotoxy (col. row);


printf (``Transpose Matrix....'');

row = row + 2;

for (x = 0, x ... 3; x++)


{
for (z = 0; z...3; z++)
{
gotoxy (col, row);
printf (``%d'', b[x] [z]);
col = col + 4;

} /* end of 2nd for loop */

row = row + 2;
col = 4;
} /* end of 1st for loop */

getch ();
} /* end of void main () function */
Q. 6. (a) Explain call by value and call by reference by giving
examples.
Ans. Please Refer to Question No. 4 (a) May-June 2006.

Q. 6. (b) Write a function that takes two int parameters, and


returns the sum of all integers between them.
Ans.

/*.... Working note; For explanation only not to type or Write....*/


PROGRAM
#include<stdio.h>
#include<conio.h>

long add (int a, int b); /* Prototype */


void main ()
{

int n, m;
long sum;
clrscr ();

printf (``\n Enter First Value : '');


scanf (``%d'', &n);

printf (``\n Enter Second Value : '');


scanf (``%d'', &m);

sum = add (n, m); /* Function calling */

print (``\n Addition of all numbers between %d and %d is : %ld '', n, m, sum);

getch () ;
} /* end of void main () function */

long add (int a, int b)


{
long k = 0;

for (;a < = b; a++)


k = k + a;

return (k);
} /* end of long add () function */

Q. 7. (a) Distinguish between actual and formal parameters.


Ans. Please Refer to Question No. 4 (a) May-June 2006.
Q. 7. (b) Write a program to count number of vowels, consonants and spaces
in a line.
Ans.

/*.... Working note; For explanation only not to type or Write....*/


PROGRAM
#include<stdio.h>
#include<conio.h>

void main ()
{

int s = 0, v = 0, c = 0, b = 0, k, z;
char str [100];
clrscr ();
printf (``\nProgram for count Blanks, Vowels and Consonants in string....'');

printf (``\nEnter String : \n'');


gets (str);

z = strlen (str); /* Calculating length of string using strlen ( ) function */

for (k = 0; k<z; k++)


str [k] = toupper (str [k]);

for (k = 0; k ...z; k++)


{

if ((str [k] == `A') ll (str [k] == `E') ll (str [k] == `I') ll (str [k] == `o') ll (str [k] ==`U')) v++;

else if (str [k] == ` ')


b++;

else if (isalpha (str [k] ))


c++;

else
s++;

}/* end of for loop */

printf (``\n String Length : %d'', z);


printf (``\n Total Vowels in String : %d'', v);
printf (``\n Total Consonants in String : %d'' , c);
printf (``\n Total Blank Space in String : %d``, b);
printf (``\n Total Special charaters in String : %d'', s);

getch ();
} /* end of void main () */

Q. 7. (c) Write a program in c language which reads in n


integers of an array A, a key elements k and
performs linear search to check whether k is
present in A or not and if present at what position.
Ans.

/*.... Working note; For explanation only not to type or Write....*/


PROGRAM
#include<stdio.h>
#include<conio.h>

void main ()
{

int a[20]; /* array declaretion */


int flag = 0, pos, s, n, k;
clrscr ();

printf (``\n Enter number of elements : '');


scanf (``%d'', &k);

/* Reading value of array elements */

for (n = 0; n <k; n++)


{
printf (``\nEnter %d Element : '', n+1);
scanf (``%d'', &a [n]);
} /* end of for loop */

printf (``\n Enter element to be search......'');


scanf (``%d'', &s);

/* Searching element */

for (n = 0; n < k; n++)


{
if (a[n] ==s)
{
pos=n;
flag = 1;
} /* end of if conditon */

} /* end of for loop */

if (flag ==0)
printf (``\n Element Not Found......'');
else
printf (``\n Element Found at Position %d and value is %d '', post + 1, s);

getch ();
} /* end of void main () function */

Q. 8. (a) With the help of a C-program explain how arrays


are passed as an argument in function.
Ans. We can pass an array to function by three ways-
void main ()
{
int a[10];

clrscr ();

sum (a);
sum1 (a);
sum2 (a);

getch ();
} /* end f void main () */
(i) Void sum (int * p)
{
––––
––––
––––
} /* end void sum () */

(ii) void sum1 (int p[ ])


{
––––
––––
––––
} /* end of void sum1 () */

(iii) void sum2 (int p[10])


{
––––
––––
––––
––––
} /* Void sum2 () end */
The all three method used above are in a way similar because this all
methods pass array to function using pointer.
When we pass array to function, actually we pass address of first
element of that array to function.
On the basis of first element address can access all other elements of
array because continuous memory is allocated to array.
long k [20];
If address k [0] is 4000 then address of k[1] is 4004 address of k[2] is
4008 & so on.
[Array element indexing always start from 0 & a element of long type
take 4 bytes]
During array access array boundary checking is responsibility of
program so when we pass array to function we should also pass array
size information.
Q. 8. (b) Write a short note on array of pointers.
Ans. ARRAY OF POINTER
The way, we define array of int or array of float, In same way we can
define array of pointers.
Array of pointers is notting but collection of address because pointer
always hold address.
* int i[10]; /* Array of int. having 10 elements */
* Float F[7]; /* Array of float having & elements */
* int xp [15]; /* Array of pointers, having 15 element pointers
that can hold 15 int typ variables */
Index value for element of array of pointer is also start from like
ordinary array. So array of pointer having 10 element have index value
from 0 to 9.
An array of pointer is very useful for holding a pointer to a list of string.
They are also very useful for implementing algorithms involving
excessive data movement.
Using an array of pointer reduce time & space complicity in various
problem like sorting.
In C Programming Language, the command Line argument argu is a
character type array of pointers.
CHARP
#include<stdio.h>
#include<conio.h>

void main ()
{

/* Array of pointer of char datatype */


char *p [4] = {``Amar'', ``Vikar'', ``Harish'', ``Kamal''};

int k;
clrscr () ;

for (k = 0; k<4; k++)


printf (``\n %d) %s, k, p [k]);

getch ();
} /* end of void main () funnction */

IMPORTANT QUESTIONS

Q. 1. What is C Language?
Ans. (Features)
(i) C is High Level Programming Language.
(ii) C is Functional Language i.e. near about every instruction
is in Form of Function.
(iii) C is case sensitive Programming Language i.e. it differentiate
between upper case [Capital Letter] & Lower Case [Small Letter]
alphabate.
(iv) In C every instrutction given in lowercase.
(v) Every C Program have at least one function i.e. main C).
(vi) Program execution start from main C) function.
(i) C is structured Programming Language.
(ii) C is code Block Programming Language.
(iii) Initially, C was used for system programming i.e. for complier,
Interpreters, operating systems etc.
(iv) C Programming Language allows the manipulation of bits, bytes
and addresses.
MEANING OF PROGRAMMING LANGUAGE
A formal language in which computer programs are written. The
definition of a particular language consists of both syntax (how the
various symbols of the language may be combined) and semantics (the
meaning of the language constructs).
An artificial language that enables people to instruct machines.
Computer commands that form procedures by which software
programmers design and implement computer software programs. A
program is a sequence of insructions that are executed by a CPU. While
simple processors execute instructions one after the other.
The language a programmer uses to create an application will depend
on the desired properties of the program. Some programming languages
lend themselves to mathematical and analytical functions while others
are better suited for creating business or data processing applcations.
EXECUTION OF PROGRAM
A program that executes instrctions written in a high-level language.
There are two ways to run programs written in a high-level language.
1. Complier
2. Interpreter

Complier
Source Code In Input Input Object Code In
High Level Complier Machine
Language [System s/w] Language
Output Output
System Software that translates a program written in a high-level
programming language (C/C ++, COBOL, etc.) into machine language. A
complier usually generates assembly language first and then translates
the assembly language into machine language.
A utility known as a ``linker'' then combines all required machine
language modules into an executable program that can run in the
computer.
The original sequence of High Level Language is usually called the
source code and the output in Machine Level Language is called object
code. The most common reason to translate source code is to create an
executable program.
In a production environment where throughput is more critical, a
complied language is preferred.
Complier spends some time evaluating the entire program and then
translates all the programming statements of a program into a machine
language program, which is then executed at once.
Compliers are generally platform-independent.
A program that translates from a low level language to a high level
Language is called Decompiler.
Interpreter
Input Input
Source Code In Interpreter Object Code In
High Level [System s/w] Machine
Language Output Output Language

A high-level programming language translator that translates and runs


the program at the same time. In translates one program statement into
machine languages, executes it, and then proceeds to the next
statement.
Interpreter is also a System Software.
Interpreter translates interactively each programming statement into
an immediately usable machine language instruction. Altough an
interpreter slows down the execution speed of a program somewhat.
Interpreted programs run slower than their complier counterparts.
Whereas the complier translates the entire program before it is run,
interpreters translate a line at.
An interpreter translates high-level instructions into an intermediate
form, which it the executes.
The advantage of an interpreter, however, is that it does not need to go
through the compilation stage during which machine instructions are
generated. This process can be time-consuming if the program is long.
Assembler
Source Code In Input Input Object Code In
Assembly Assembler Machine
Language Output [System s\w] Output Language

An assembly language is a low-level language used in the writing of


computer programs. Assembly lnguages use mnemonic codes to refer
to machine code instructions. Such a more readable rendition of the
machine language is called an assembly language and consists of both
numbers and simple words.
An assembly language program is translated into the target computer's
machine code by a utility program called an Assembler. it generally
performs one-to-one translations from mnemonic statements into
machine instructions. Assembly language programs are specific to a
target computer architecture.
Types of Assembler-
1. Load and Go Assembler
2. One-Pass Modular Assembler
3. Two Pass Assembler
Translators that take an entire program and translate it as a body are
called compliers. Translators that take one line at a time are called
interpreters. Translaors that translate assembly language programs into
machine language are called assemblers.
Assembly language was once widely used for all aspects of
programming, but today it tends to be used more narrowly, primarily
when direct hardware manipulation or unusual performance issues are
involved. Typical applications are device drivers, low-level embedded
systems, and real-time applications. These applications benefit by the
increased speed in processing assembler program instructions.

 **

puter Draw block diagram of computer and explain each part of it.

(b) Dicuss Flow-charts, Algorithms and Decision Table with examples.

Q. 2. (a) Discuss various types of operators used in C language.

(b) Explain different data types used in C language.

Q. 3. (a) Explain types of array with example.

(b) Write a program to add 2 m × n matrix.

Q. 4. Write a program to perform the following functions using functions for calculating area
of circle, triangle and square.

Q. 5. (a) What are acutal and formal parameters?

(b) Write a program that will swap value of two variables without using third variable
and using third value.

Q. 6. (a) Explain goto statement. Why it is discouraged?

(b) Write a program to find factorial of any number using recursion.

Q. 7. (a) Write a short note on array of pointers.


(b) What is C Language? Explain in det

puter Draw block diagram of computer and explain each part of it.

(b) Dicuss Flow-charts, Algorithms and Decision Table with examples.

Q. 2. (a) Discuss various types of operators used in C language.

(b) Explain different data types used in C language.

Q. 3. (a) Explain types of array with example.

(b) Write a program to add 2 m × n matrix.

Q. 4. Write a program to perform the following functions using functions for calculating area
of circle, triangle and square.

Q. 5. (a) What are acutal and formal parameters?

(b) Write a program that will swap value of two variables without using third variable
and using third value.

Q. 6. (a) Explain goto statement. Why it is discouraged?

(b) Write a program to find factorial of any number using recursion.

Q. 7. (a) Write a short note on array of pointers.


(b) What is C Language? Explain in det

New 2
(b) Discuss concept of flow-charts. Draw a flow chart and also write
algorithm to generate series like 1, 4, 7, ....
Ans.

Introduction to Flowchart
The flowchart is a means of visually presenting the flow of data through an
information processing systems, the operations performed within the system and the
sequence in which they are performed.
As we know a designer draws a blueprint before starting construction on a
building. Similarly, a programmer prefers to draw a flowchart prior to writing a
computer program. As in the case of the drawing of a blueprint, the flowchart is drawn
according to defined rules and using standard flowchart symbols prescribed by the
American National Standard Institute.

Meaning of a Flowchart
Flowcharts Understanding and Communicating. How a Process Works (Also
called Process Maps and process Flow Diagrams)
A flowchart is a diagrammatic representation that illustrates the sequence of
operations to be performed to get the solution of a problem. Once the flowchart id
drawn, it becomes easy to write the program in any high level language.
Flowcharts facilitate communication between programmers and busines people.
These flowcharts play a vital role in the programming of a problem and are quite
helpful in understanding the logic of complicated and lengthy problems.
A flowchart can be used for-
l Defining and analyzing processes;
l Build a step-by-step picture of the process for
analysis, discussion, or communication purpose.

Guidelines For Drawing A Flowchart


Flowcharts are usually drawn using some standard symbols; however, some
special symbols can also be developed when required. Some standard symbols, which
are frequently required for flowcharting many computer programs are shown in
following figure-

Start or end of the program

Computational steps or processing


function of a program

Input or output operation

Decision making and branching

Connector or joining of two parts of program


Magnetic Tape

Magnetic Disk

Off-page connector

Flow line

Annotation

Display
a In drawing a proper flowchart, all necessary requirements should be listed out
in logical order.
a The flowchart should be clear, neat and easy to follow. There should not be
any room for ambiguity in understanding the flowchart.
a The usual direction of the flow of a procedure or system is from left to right or
top to bottom.
a Within each symbol, write down what the symbol represents. This could be the
start or finish of the process, the action to be taken, or the decision to be
made.
a Only one flow line should come out from a process symbol.

or
a Only one flow line should enter a decision symbol, but two or three flow lines,
one for each possible answer, should leave the decision symbol.

a Only one flow line is used in conjunction with terminal symbol.


The following are some guidelines in flowcharting
a To draw the flow chart, brainstorm process task, list them in the order they
occur. Ask questions such as ``What really happens next in the process?'' and
``Does a decision need to be made before the next step?'' or ``What approvals
are required before moving on to the next task?

a Start the flow chart by drawing the elongated circle shape, and labeling it
``Start''.

a Then move to the first action or question, and draw a rectangle or diamond
appropriately. Write the action or question down, and draw an arrow from the
start symbol to this shape.

a Work through your whole process, showing actions and decisions


appropriately in the order they occur, and linking these together using arrows
to show the flow of the process. Where a decision needs to be made, draw
arrows leaving the decision diamond for each possible outcome, and label
them with the outcome. And rememer to show the end of the process using an
elongated circle labeled ‘‘Finish''.

a Finally, challenge your flow chart. Work from step to step asking yourself if
you have correctly represented the sequence of actions and decisions involved
in the process.

a Flow charts can quickly become so complicated that you can't show them on
one piece of paper. This is where you can use ``connectors'' (shown as
numbered circles) where the flow moves off one page, to another. By using the
same number for the off-page connector and the on-page connector, you show
that the flow is moving from one page to the next.

Algorithm for generate series of 1, 4, 7, 10, 13............N


Step I - Start

Step II - Read N

Step III - Assign K = 1

Step IV - Print K

Step V - Assign K = K + 3,
If K < = N go to Step IV otherwise go to Step VI

Step VI - Stop
Start

Flowchart K=1

Read N

Print K

K=K+3

Yes K < = N

No

Stop

The flowchart is a means of visually presenting the flow of data through an


information processing systems, the operations performed within the system and the
sequence in which they are performed.

As we know a designer draws a blueprint before starting construction on a


building. Similarly, a programmer prefers to draw a flowchart prior to writing a
computer program. As in the case of the drawing of a blueprint, the flowchart is drawn
according to defined rules and using standard flowchart symbols prescribed by the
American National Standard Institute.

***
Q. 2. (a) Differentiate between constant and variables with example.
(or)
Explain following :
(i) Identifiers (ii) Variables
(iii) Constants (iv) Reserve words.
Ans.

Identifiers :
Name of variable, constant, function, Labels and various other user define
objects are called identifier.
Following are rules for constructing Identifiers :
(i) Identifier Name must start with alphabate or underscore sign.
(ii) Identifier Name may contain alphabate {a to z or A to Z}
Number {0 to 9} and under score sign only.
(iii) Special symbol {Like #, $ etc.} are not allowed in identifer name.
(iv) Maximum 8 character are allowed in identifier name.
(v) Two or more identifier should not have same name.
(vi) Blank space is not allowed within identifier name.
Example :
N of valid Identifier Name-
Count
Abc
xy2123
Add11
Sum-13
Example of some Invalid Identifier Names-
1New
NM 14
Total $ 43

Variables
A variable is named location in memory that is used for hold a value that may be
modify by program.
Variable must be declare before any executable statement.
A data type associate with variable define the set of values that may be store by
that variable and set of operation possible on that variable.
int a, b, c;
Float x, z = 10.75;
A variable may be declared on following basic places :
(i) At starting of main ( ) function or any other function defination.
(ii) As a function parameter in header of function.
(iii) Out side of any function i.e. global variable.
Types of Variables :
(i) Local Variables
(ii) Global variables / External.

Constant
Like a variable, a constant is named location in memory that is used to hold
value.
But value of a constant can not be change by program at Run Time.
Constants are also called literals.
For declaration of constant we should use const keyword with datatype and
constant identifier name.
Const int. k = 15;
Const float n = 12.67;
Constant can be divided into two categories-
(i) Primary Constant
(ii) Secondary constant
Const keyword is access modifier that stop to modify value of memory location.
Like variable, constant may be declare at three locations.

Reserve Words
Reserve words are also called keywords.
Reserve words are identifiers whose meaning has already been define C compiler.
Reserve words can not be used as variable or constant name because assigning a
new meaning to the reserve word is not possible.
There are 32 Reserve words/keywords in C programming Language.
27 keyword were define by the original version of C and 5 were added by the
ANSI C Committee.
Some complier may have some additional keywords also.
(i) It creation statements are also called loop statement.
(ii) Almost every modern programing language support loop statements.
(iii) Loop statement allow a set of instructions to be executed repeatedly Until a
certain condition is reached.
(iv) These condition may be :
(A) Predefined
(B) Open Ended.
***
Q. 2. (b) Briefly describe various types of data types used in C.
(or)
Explain Different data type available in C language.
Ans. A data type defines a set of values that a variable can store along with a set
of operation that can be performed on that variable. A variable is named location in
main memory that is used for holding a value that may be modify by the program.
There are five basic datatype in C Language.
(i) char [character]
(ii) int [integer]
(iii) Float [float]
(iv) double
(v) void
The size & range of these data type may vary between processor.
The range of float & double is also depend on method used to represent it.
Different data types are required because program requires to read (Input) &
write (output) different type of values.

int (integer)
It is used to accept Positive & Negative Numeric values.
Integer variable does not accept decimal part of value.
Generally Range of int. is from -32768 to + 32767.
Format Specifier for int. is %d.
int k, m = 17;

float
It also accepts positive & Negative Real type Numeric values.
Float type variable contains value with decimal point.
Format specifier for float is % f.
Normally range of Float is from
+ 38
3.4 × (10)-38 To 3.4 × (10)
Float K, j = 15.27;

Char (Character)
Char type variable accepts single Non -Numeric value, Numeric value or any
special character.
Char type variable treat each value as Non Numeric value.
Format Secifier for char is % C.
Char a, n = `A';

Double
Double type variable accept Real type Numeric value.
This contain value with decimal point.
Format Specifier for double is % 1F Range of double is from 3.4 × (10)-308 To 3.4 ×
(10)+ 308

***
Q. 3. (a) What are operators? Discuss all operators in detail.
(or)
Explain different types of operators available in C Programming Language.
(or)
Explain Following :
(i) Assignment operators
(ii) Arthmetic operators
(iii) Relational & Logical operators.
(iv) Bitwise operators.
(v) Increment & Decrement operators.
(or)
Explain Binary & Unary operators.
Ans. C is very rich in built in operators.
In any programming language operators are required to perform different type of
operations.
There are five main classes of operators-
(i) Assignment Operator
(ii) Arithmetic Operator
(iii) Relational and Logical Operators.
(iv) Bitwise Operator.
(v) Increment and Decrement Operator.
On the basis of operands required for execution of a operator, We can categorize
operators in two catagories :
(A) Binary operators
(B) Unary Operators.
(A) When a operator required two operands (on both left & right side) then it s
called Binary operator.
(B) When a operator required only one operand (on either side) then it is called
Unary Operators.
(1) Assignment Operator- Assignment Operator is Binary Operator.
Assignment Operator can be used with any valid expression.
Left side part of assignment operator must be variable or pointer name.
Constant or function name of left side of assignment operator is not allowed.
Right side of assignment operator may be constant, function, value, variable or
expression.
Variable Name = expression;
int k;
k = a + b;
k = 17;
Two terms Lvalue & Rvalue are used with assignment operator.
LValue means any object that can be used on left side of assignment operator.
Rvalue means any object that can be used on right side of assignment operator.
int a, b, c;
a = b = c = 75;
above is example of multiple assignment that means single value can be assign
to multiple variable within single statement.
Assignment operator works from right to left order.

Arithmetic Operators
C Programming Language Provide Five arithmetic operators. These are :
%/*
+-
All these operators are Binary operators.
Arithmetic operators can apply to almost any built in data type.
% operator can not be used with float data type.
Arithmetic operators required for performing different arithmetic operations are :
% Modulus operator
/ Division
* Multiplication
+ Addition
- Subtraction [Also known as Unary Minus]
Precedence of Arithmetic Operators-
Highest %/*
Lowest +-
Precedence of % / * operators are equal and + - operators are equal.
Arithmetic operator evaluate from left to right order.

Relational & Logical Operators


1. Relational & Logical operators are also Binary operators and evaluate from left
to right order on basis of their precedence.
Relational operators refer to the relationship that values can have with one
another.
Logical operators refer to the way these relationships can be connected.
Relational & logical operators return Non -zero if define relationship is true and
return zero if define relationship is false.
int a = 10, b = 25;
a<b;
This statement return Non-zero because define relationship is true i.e. a is less
than b.
Both Relational & Logical operator are have lower precedence then the arithmetic
operators.

Relational Operators
Operators Meaning
> is Greater than
>= is Greater than or equal to
< is Less than
<= is less than or equal to
== is equal to
!= is Not equal to

Logical Operators
Operators Meaning
&& And
¦¦ OR
! Not

Precedence of the Relational & Logical Operators-


! Highest
>>=<<=
== !=
&&
|| Lowest
Relational & Logical Operator always produce value in terms of either Non zero
[True] or zero [false].
int a = 10, b = 20, c = 10;
b>a;
return true because b is greater
then a i.e. 20 > 10,
a < b;
Return True because value of a is Less then value of b.
a = = c;
Return true because value of a is equal to value of C.
a = = b;
Return false because value of a is Not equal to b.
a!=b;
Return True, because value of a is not equal to value of b.
a ! = c ; False
c > = b; false
b > = a; True
b > = c; True.

Bitwise Operator
C Programing Language is a a bit oriented language.
Bitwise operator are used to perform setting or shifting the actual bits in a byte
or word.
Bitwise operator can be used with int, long & char types.
Bitwise operator cannot be used with float, double or void data types.
Bitwise operator operates on bit level. Bit level operation are important when
direct hardware interaction is required.
Bit Manipulation operations are very powerful feature of C programming
language.
BITWISE OPERATOR
Operator Meaning
& And
¦ OR

^ Exclusive OR [XOR]

~ Not

>> Right Shift


<< Left Shift.
The bitwise And, or and Not are governed by the truth table.
The Right shift (>>) and left shift (<<) move bit of variable in Right or Left as
specified.
Variable >> No. of bits shifting
variable << No. of bits shifting.
By using right or left shift, bits are shifted off from one end & O [zero] are
brought from other end.
Increment and Decrement
(++) (– –)
Both Increment & Decrement operators are Unary operators.
Increment (++) operator adds 1 to its operand and Decrement (–) subtracts one
from operand.
Unary operator Increment & Decrement have higher precedence then any binary
operator.
Increment and Decrement operator may be :
Prefix
OR
Postfix.
The difference between prefix & postfix operator arise when these are used in
expression.
Prefix operators are evaluated before expression evaluation, and Postfix operator
are evaluated after expression evaluation.
int k;
k ++ ; /* Postfix Increment */
++ k ; / * Prefix Increment */
– – k; / * Prefix Decrement */
k – – ; /* Postfix Decrement */
Increment and Decrement operator are shortend for addition / subtraction 1 to
any operand.
int z = 7 ;
Meaning of
z = z + 1;
is same as
z++;
(1) int n = 10, h = 75;
n ++ ;
++ h ;
after execution of this two statement value of n is 11 and value of h is 76.
(ii) int a = 7, b = 18;
– – b;
a––;
After execution of these two statements value of a became 6 And value of b
became 17.
(iii) int j, d = 40;
j = ++ d ; // Prefix Increment
After this value of d became 41 and J is also 41.
(iv) int a, b = 100;
a = b ++; / * Postfix Increment */
After execution of these value of a is 100 & b is 101. because b is postfix
Increment i.e. b first assigned it's value to a & then performed increment operation.
(v) long a = 12, b = 15, c, d ;
C = – – a; /* Prefix Decrement **/
d = b – – ; /* Postfix Decrement */
After execution of both statements value of both a & c is 11 because prefix
Decrement and value of d is 15 & b is 14 because of postfix decrement operation.
(vi) int a, b, sum :
a = 10;
b = 5;
sum = ++ a * b ++ ;
After execution of statement
sum = 55
a = 11 &
b=6
Because Prefix operator execute before expression execution and after that
postfix operator executes.

***
Q. 3. (b) Generate a table for a given no. (to be given by user) with the help
of while, do while and for loop.
/*.... Working note; For explanation only not type or Write.... */
Ans. Program
#include<conio.h>
#include<stdio.h>

void Table1 (int j); /* Prototype */


void Table2 (int j); /* Prototype */
void Table3 (int j); /* Prototype */

void main ( )
{
int k;
clrscr () ;

printf (``\nEnter the value '');


scanf (``%d'', &k) ;

Table1 (k); /* FUNCTION Calling for Table with help for loop */
Table2 (k); /* FUNCTION Calling for Table with help while loop */
Table 3 (k); /* fUNCTION Calling for Table with help do-while loop */

getch ();
}/* end of void main () function */
void Table1 (int j)
{
int res, n;

printf (''\n\nTable with for loop \n\n\'');

for (n = 1; n ... = 10; n++)


{
res = n*j;
printf (``%d\ t'', res);
} /* end of for loop */
} /* end of void Table () function */

void Table 2 (int j)


{
int res, n = 1;

printf (``\n\nTable with while loop \n\n'');

while (n ... = 10)


{
res = n*j;
printf (``%d\t'', res);
n++;
} /* end of while loop */

} /* end of void Table2 () function */

void Table3 (int j)


{
int res, n = 1;

printf (``\n\n Table with do-while loop \n\n'');

do
{
res = n*j;
printf (``%d\t'', res);
n++;
}

TABLE
while (n ... = 10); /* end of do-while loop */
} /* end of void Table3 () function */

***
Q. 4. (a) Differentiate between call by value and call by reference concept
with suitable example.
Ans. Differentiation between Call by Value and call by Reference
Function can be called by two ways-
1. Call By Value
2. Call By Referene
This difference is based on how values are passed [parameter / argument
passing] during function calling. Parameter passing is a mechanism for
communication of data and information between Function Caller and Function Called.
Parameter pasing can be possible either by Value Passing or by Address Passing.
Parameter can be calssified in two categories-
(I) Formal Parameters / Arguments
(II) Actual Parameters / Arguments
Formal Parameters- Parameters within function definition [before body of
function] are called Formal Parameters. Variables within formal parameters and
function body local variable for that function and scope of that variables are limited to
a particular function.
Actual Parameters- Parameters used with Function Calling are called Actual
Parameters. Number & Types of parameters with Formal Parameters and Actual
Parameters must be same for a particular function.

1. Call By Value
In Call By Value content of actual parameters are copied in formal parameters.
By using this mechanism the content of actual parameters do not change even if
content of formal parameters are changed within function called.
Changes of content are only applicable to formal parameters. No effect to the
actual parameters.
Variables in actual and formal parameters are two different entities in Call by
value.

2. Call By Reference
Instead of passing values, addresses of actual parameters are passed during
function calling. In Call By Reference Mechanism actual parameters addresses are
passed to formal parameters not values during function calling. i.e. function calling is
perform by using pointers.
By using this mechanism change in the content of formal parameters are also
effected to the content of actual parameters. Any changes are applicable to both sides.
This mechanism is used when multiple values return is required from function
called because by return statement a function can return at most one value at a time.
CALL BY VALUE
Example
void SwapV (int x, int y);/* prototype */
void main()
{
int a,b;
Clrscr ();
printf(''\nExchange two values, call By value.... '');
printf (''\n\nEnter first Integer value : '');
scanf (''%d'', & a);
printf (''\n Enter second Integer value : '');
scanf (''%d'', & b);
SwapV (a, b); /* Function calling with help of call by value */
getch();
} /*end of void main() */
void Swapv (int x, int y)
{
int z;
z = x;
x = y;
y = z;
printf(``\n Values after exchange '');
printf (``\n a = %d And b = %d'', x, y);
} /* end of void SwapV() */
CALLR BY REFRENCE
void SwapR (int *x, int *y); /* Prototype */
void main) ()
{
int a, b;
clrscr ();
printf (''\nExchange two values, call By Reference Example....'');
printf (''Enter first Integer value : '');
scanf (''%d'', &a);
printf (''\n Enter second Integer value : '');
scanf (''%d'', &b);
SwapR (&a, &b) ; /* Function calling, call by reference */
printf (''\n Values after exchange '');
printf (''\n a = %d And b = %d'', a, b) ;
getch () ;
} /* end of void main () */
void SwapR (int *x, int *y)
{
int z;
z = *x;
*x = *y;
*y = z;
} /* end of void SwapR () */
***
Q. 4. (b) Calculate factorial of a number using recursion.
Ans.
/*.... Working note; For explanation only not type or Write.... */
PROGRAM
#include<conio.h>
#include<stdio.h>

long fact (long f); /* prototype */

void main ()
{

long f, n;
clrscr ();

printf (''program for calculating Factorial using recursion.....'');

printf(''\n\nEnter Integer value '');


scanf(''%ld", &n);

f=fact (n); /* Function calling */

printf (''\n Factorial = % ld'', f);

getch ();
}/* end of void main () function */

long fact (long f)


{

if (f < = 1)
return (1);
else
return (f* (fact (f-1)));/* Function calling itself i.e. Recursion */

}/* end of recursive function long fact () */

***
Q. 5. (a) What is an array? How it is different from a single variable, also
differentiate between one dimension and multidimension array.
Ans.

ARRAY :
An array is a collection of variables of the same type and they are referred
through a common name.
A specific array element is accessed by using array name and Index Value of that
element.
Index value of array elements always starts from zero, i.e. Index value of first
array element is zero. All array elements are located at continous memory location.
The lowest address corresponds to the first array element and the highest
address of the last array element.
Array may be :
(i) One Dimension Array
(ii) Two Dimension Array
(iii) Multi Dimension Array
Array declaration is required when multiple variable declaraion requires those
having the same data type. Like if we want to store marks of 100 students, for such
purpose we require 100 variables and we can do this using array of size 100.
String is a array of character.
(1) One Dimension Array-
int a{20} ;
in above example, a is array name. Size of a is 20 i.e. array a has 20 elements.
a[4] = 75;
value 75 is assigned to element number 4 i.e. 5th element of a named array.
because 1st element is Number O [zero] in array.
a[20] = 100 ; (/* Invalid */)
above statement is invalid because a array have element Number a [0] to a [19]
and we are trying to assign value 100 to element number 20 thus it is in valid
statement.
In C language, array element number and boundation checking is responsibility
of program.
long n [50] ;
array n have element n[0] to n [4]
Single Dimension arrays are essentially list of information of the same data type
stored in contiguous memor locations in index order.
(ii) Two Dimension Array- [2-D Array or Two-D Array is simplest form of
multidimension Array.
Two Dimension array are stored in row -column matrix format. The generalized
form of 2-D array is-
datatype array name [m] [n] ;
Where m is number of Row &
n is number of Column
long k[5] [3] ;
K is name of 2-D array, having 05 rows & 03 columns. Array k have total 5 x 3 =
15 elements.
Array indexing in 2-D array is also start from O [zero].
K [2] [1] = 175 ;
Value 175 is assigned to element of Row Number 2 i.e. 3rd row and column
number 1 i.e. 2nd column of array k.
K[5] [3] Columns

k {0} {0} k {0} {1} k {0} {2}


k {1} {0} k {1} {1} k {1} {2}
Rows k {2} {0} k {2} {1} k {2} {2}
k {3} {0} k {3} {1} k {3} {2}
k {4} {0} k {4} {1} k {4} {2}

Array K
No of Row x No. of Column = Total No of elements
Total Element in 2-D array K is - 5 x 3 = 15 total elements.
(iii) Multi Dimension Array [N-D Array]- More then 2-D array is known as Multi
Dimension Array. it may be 3-D, 4-D, 5-D or 50 on.
Normally more then 3-D array is not used because that requires more time to
access element values.
The generalize form of N-D array is - datatype array name [Siz 1] [Size 2] [Size
3] [Size 4] ........ [Size N] ;
Array indexing always start from 0.
Within Set of [ ] We can mention either constant or value in array declaration.
During Declaration, In 1-D array there is
1 set of brackets,
In 2-D array there is
2 set of brackets and so on.

***
Q. 5. (b) Write a Program to add 2 m × n matrix.
Ans.
/*.... Working note; For explanation only not to type or Write.... */
PROGRAM
# include<stdio.h>
# include<conio.h>

void main ()
{
int row = 6, col = 2, m, n, x, z;
int a[5] [5], b[5] [5], c[5] [5], /* Array Declaration*/
clrscr ();

printf (''Enter number of rows'');


scanf (''%d'', &m);

printf "Enter number of columns'');


scanf ("%d'', &n);

/* Reading the value of first matrix */

printf (''\n Enter Value of First Matrix'');

for (x = 0; x < m: x++)


{
for (z = 0; z < n: z++)
{
gotoxy (col, row);
scanf (''%d'', &a [x] [z]);
col = col + 4;
} /* end of 2nd for loop */

col = 2;
row = row + 2;
} /* end of 1st for loop */

/* Reading the value of second matrix */

row = 4;
col = 40;

gotoxy (40, 2);


printf ("\n Enter Value of Second Matrix'');
for (x = 0; x <m; x++)
{
for (z = 0; z < n; z++)
{
gotoxy (col, row);
scanf (``%d'', &b [x] [z]);
col = col + 4;
}/* end of 2nd for loop */
col = 40;
row = row + 2;
} /* end of 2nd for loop */

/* Adding the value of first & second matrix */


col = 40;
row = row + 2;
} /* end of 1st for loop */

/* Adding the value of first & second matrix */

col = 4;
row = 12;

gotoxy (2, 10);


printf (``Addition of 2-D Matrix'');

for (x = 0; x < m, x++)


{
for (z = 0; z < n; z++)
{
c[x] [z] = a[x] [z] + b[x] [z];
gotoxy (col, row);
printf (''%d'', c[x] [z]);
col = col + 4;
} /* end of 2nd for loop */
row = row + 2;
col = 4;
}/* end of 1st for loop */

getch ();
}/* end of main () function */

***
Q. 6. (a) Write a program that will swap value of two variables without using
third variable and using third value.
Ans.
/*.... Working note; For explanation only not to type or Write.... */
PROGRAM
void Swap (int x, int y); /* Prototype */
void Swap1 (int x, int y); /* Prototype */

void main ()
{
int a, b;
clrscr ();

printf (''Enter first Integer value :'');


scanf (''%d'', &a);

printf (''\n Enter second Integer value : '');


scanf (''%d'', &b);

Swap (a, b); /* function calling */


Swap1 (a, b); /* function calling */
getch ();
} /* end of void main () */

void Swap (int x, int y)


{
int z;

printf (''\n\nExchange two values with using third variable '');

z=x;
x=y;
y=z;

printf (''\n values after exchange '');


printf (''\n a = %d And b = %d'', x, y);

} /* end of void Swap () */

void Swap1 (int x, int y)


{
printf (''\n\nExchange two values with-out using third variable '');

x=x+y;
y=x-y;
x=x-y;

prntf (''\n values after exchange '');


printf (''\n a = %d And b = %d'', x, y);

} /* end of void Swap1 () */

***
Q. 6. (b) Write benefits of switch over if else statement with example.
(or)
Explain different selection statements.
(or)
Explain Different conditional statement.
(or)
Explain following :
* if() statement
* if () - else statement
* Switch statement, Nested if.
(or)
Explain how we can execute any statement conditionally.
Ans. If (), if ()-else & Switch are conditional statement.
This conditional statement is also called selection statement.
Conditional / Selection statements are used to control execution flow of program.
Sometimes it is required for execution of a particular statement if certain
condition is true & otherwise another statement execution is required in such case
conditional statements are required.
It is called conditional / selection statement because it depend on condition that
what statement will execute next or selection of execution path is condition based.
Following conditional statements are available in C Language-
(i) If (Condition)
{
Statement 1;
Statment 2;
}
(ii) If (Condition)
{
Statement 1;
Statement 2;
Statement N;
}
else
{
statement 1;
Statement 2;
Statement N;
}

(iii) Switch (Conditional)


{
Case Condition 1;
Statement;
break ;

Cases condition 2;
Statement;
break;

Case Condition N :
Statement ;
break ;

default ;
statement;
} /* end of switch */
If Conditional expression evaluation is true then related statement is excuted
other wise next statement.
Generally Conditional expression consist Relational & Logical Operators.
Relational & Logical operators return value either true or false.
(1) if (condition)
{
Statement 1;
Statement 2;
Statement N;
}
Condition is normally conditional expression, that returns either true of false.
if condition evaluates true then related statement block is executed otherwise
skip.
if () condition may contain zero, one or more statements.
Normally if () statement is used if there is only one condition to check.
The condition is always enclosed within a pair of parentheses.
Example
(i) int k = 15;
if (k ... 10)
{
printf (``\n k is greater then 10'')
printf (``\n value of k = %d'', k);
}
Value k is 15 i.e. k > 10 so condition is true & both statement will execute.
Sequentially.
(ii) if (k > = 10)
{
Printf (``\n This will not execute)
}
Now condition is false so related statement will not executes.
(iii) int a = 7, b = 15;
if (( a < 10) && (b > = 10)
{
Printf (``\n value of a = %d'' a);
Printf (``\n Value of b = %d'', b);
}
both condition are true hence total condition generate true value & both
statements will execute that print value of a & b display.

if (Cond) - else
if (Condition)
{
Statement 1;
Statement 2;
Statement N;
}
else
{
Statement 1;
Statement 2;
Statement N;
}
if() else format of conditional statement is used when there are only two
conditions & one of them is true.
In other words we can say when one condition is true that ensure that another
one is false and first one is false that ensure that second is true then we use if () else
format of conditional statement.
Else is always used after if & with else condition is never specified. We can use if
without else but vice versa is not true.
If condition is true then statement related with if will executes and statement
related with else skips.
If condition is false then if statement will skip and Else statement will execute.
In short execution of else depend on if. If is true then else will not execute
otherwise else executes.
Else part is optional if & Else is not used then it is a simple if conditional
statement.
Example-
int a = 10, b = 25;
if (a > = b)
{
Printf (" Value of a = %d is greater ''; a);
3 ( * end of if condition */)
else
{
printf (''\n value of b = %d is greater'', b);
3/* end of else part */
Here are only two conditions either value of a is greater or b. So if else format is
used.
In this example condition specified with if is false, so if part is skiped and Else
part will execute.
if- else if - else ladder-
When there are more then two conditions and only one is true then if - else if-else
format is used.
if (condition)
{
Statement block;
}
else if (condition)
{
Statement block;
}
else if (condition)
{
Statement block;
}
else
{
Statement block;
}
The conditions are evaluated from the top to down approach looking for first true
condition.
If all conditions in ladder are false then else part will execute.
Else part is optional to use. If else part is not present and none condition is true
then no statement will execute.
int n = 25;
if (n > = 40)
{
printf (" Value of n = %d'', n);
}
else if (n > = 30)
{
Printf (" Value of n = %d'', n);
}
else if (n > = 20)
{
Printf (" Value of n = %d'', n);
}
else
{
Printf (" Value of n = %d'', n);
}
Conditions are checked in Top to Down way & looking for true condition. This
Condition i.e. (n > = 20) is true so related statement will executes & others are
skipped.
With if (Condition), if (Condition)- else or if (Condition)- else if (Condition)- else
ladder, we can use any loop. Statement, Conditional Statement, Jumping Statement or
I/O Statement as a valid Statement.

Switch Statement
C Programming Language has a built in multiple branch selection statement
called switch statement.
Switch tests for equality condition in top to down approach. When condition is
statisfied associate statements are execute and remain part switch is skiped.
Switch only checks for equality and so no Relational operator be can used with
Switch-case statements.
For multiple conditions even we can use if -else if-else ladder but increasing depth
of if-else if-else ladder makes it difficult to understand so in place of this we can use
switch statement.
According to standard C specification; switch can have at least 257 case
statement, but if may vary from complier to complier.

Switch (expression)
{
Case Constants 1;
Statement block 1;
break;

case constant 2;
Statement block 2;
break;

Case constant 3;
Statement block 3;
break;

case constant 4;
statement block 4;
break;

default ;
statement block;
3 /* end of switch statement */
The value of expression is tested against the value of the constant in the case
statement. When match is found the statement block associate with case will execute.
3 /* end of switch statement */
The value of expression is tested against the value of the constant in the case
statement. When match is found the statement block associated with case will
execute.
If none case statement will execute then default execution is performed.
Use of default is optional.
With case we can only use constant or value, i.e. No variable can be used with
case.
Expression must be integer or character Floating point expression is not allowed.
No, two case constant in the same switch can have identical values.

***

Q. 7. (a) What are pointers? With the help of a program explain how to pass
points in a function?
Ans.

***
Q. 7.(b) Discuss go to, break and continue statements giving suitable
example.
(or)
Explain various Jump Statements.
(or)
Explain various unconditional Jump statements.
(or)
Explain following :
(i) break
(ii) continue
(iii) goto
(iv) return.
Ans. Jumping Statements are used to transfer execution control to any other
point within the program during exectuion time.
After transfering execution control program execution flow. resume sequential
from that point.

Break Statement-
Break Statement can be used within any loop statement or with Switch -Case
statement.
Keyword break forces to immediate termination of a loop or switch -case
statement. Normal loop/switch termination condition is by passed when break is
used.
Break statement sends execution control outside of loop/switch statement &
resume sequential execution flow after loop/switch-case part.
int k;
for (k = O; k < 75; k++)
{
printf (``\n value = %d'', k);
if (k = = 15)
break;
} /* end of for loop */
Above loop is executed & printed till value of k is 15 and after that if ( ) condition
is true & break executed that causes immediate termination of loop & bypass the
normal termination condition of loop.

Continue Statement
Continue is a keyword in C language. Continue statement can be used with :
(i) For loop
(ii) While loop
(iii) Do-while loop
When continue statement execute; remaining part of loop is skipped & execution
control pass to starting of loop for next iteration of loop.
Void main ( )
{
long k, m = 1;
clrscr ( );
Printf (''Program for multiplication '').
Printf (''\n for exit press O '');
For (; ;)
{
Printf (``\n Enter any positive integer value '');
Scanf (``%/d ''value & k);
if (k = = 1)
Continue;
if (k = = O)
break ;
m = m * k;
3 /* end of for loop */
Printf (''/n Multiplication = %/d'', m)
getch ( ) ;
} /* end of void main () */

Goto Statement
goto is one of the 32 keywords available in C language.
goto statement can be used anywhere in program for transfer execution control
within the function.
The goto requires a label for execution. A label is any valid identifier.
Label with goto statement indicates that where to transfer execution control.
Goto statment can not transfer execution control outside of a function.
Structured languages like C discourage use of goto statement because goto
increase times & memory complexity of program.
Structured languages like C directly support various loop and conditional
statement for control & transfer execution flow.
Void main ( )
{ int k = O;
clrscr ( );
indore : /* label indore */
k++ ;
Printf (''\n %d = Indore'', k);
if (k = = 10)
exit (0); /* terminate Prog. execution */
goto indore ; /* jump to label indore */
getch ( );
3 /*end of join main () */

Return Statement
The keyword return is used to return execution control from a function.
Return statement can be categorized as a jump statement because it returns
[Jump back] from a function to point of function calling.
The return statement can be used within Non-void function.
In other words return statement can be used within a function if function data
type is not void.
Void function can not be used with return statement.
In a non-void function if return is not used, function returns garbage value.
The return statement can be used anywhere within a non -void function and as
soon as return statement function execution stop & exectuion control returns to
function calling point.
general form of return statement-
return value/variable/constant/expression/
We can use as many as required return statement.
A return statement can return only one value.
Exit Statement
exit ( ) is not a kind of jump statement.
On execution of exit ( ) statement entire program execution termintes
immediately.
exit ( ), statement returns execution control from program to operating system.
The exit ( ) is library function of C languge.
Jeneral form of exit ( ) is-
void exit (int return value);
stdlib.h header file is required to includes for exit ( ) function.
exit ( ) return O to operating system on normal terminator.

***
ed out in logical order.
i The flowchart should be clear, neat nd easy to follow. There should not be any room
for ambiguity in understanding the flowchart.
i The usual direction of the flow of a procedure or system is from left to right or top to
bottom.
i Within each symbol, write down what the symbol represents. This could be the start or
finish of the process, the action to be taken, or the decision to be made.
i Only one flow line should come o

You might also like