Академический Документы
Профессиональный Документы
Культура Документы
BCA- (B)
[Question-1]
(1) Start/End =
(2) Action/Process =
Binty, Brinda, Ami F.Y.BCA- (B)
(5) Decision/Condition =
(3) Give two features which makes ‘C’ a very popular language.
Ans:-
(i) It is a robust language whose reach set of built in function and operator
can be used to write complex programs.
(iii) Programs written in ‘C’ are efficient and fast. It has verity of data types
and powerful operators.
(iv)There are only thirty-two key words and several built in functions which
are used for developing programs.
(v) ‘C’ is highly portable. This means that ‘C’ programs written for one
computer can be run on another computer with little or no modification.
Binty, Brinda, Ami F.Y.BCA- (B)
(vii) An importance feature of ‘C’ is its ability to extend its self. We can
continuously add our own functions to the ‘C’ library.
(2)Problem-oriented language:-
It is defined as follows,
enum identifier(value1,value2,…,valuen);
The enumerated variables v1, v2,…, vn can only have one of the values
value1, value2,…,valuen.
An example;
The compiler automatically assigns integer digits beginning with 0 to all the
enumeration constants. This is, the enumeration constants value 1 is assigned
0, value2 is assigned 1, and so on. However, the automatic assignments can
be overridden by assigning values explicitly to the enumeration constants.
Ans: - X=7.
Binty, Brinda, Ami F.Y.BCA- (B)
Example:
X+Y*Z/(W+1)
Example:
While(x>0)
{
Total = Total + Item[x];
x=x-1;
}
Constants
Binty, Brinda, Ami F.Y.BCA- (B)
Numeric Character
Integer constants:-
An integer constant refers to sequence of digits. There
are three types of integer.
(1)Decimal
(2) Octal
(3) Hexadecimal
Real constants:-
[Question-2(A)]
Binty, Brinda, Ami F.Y.BCA- (B)
(1)Start
(2)Define t1=1, t2=0, t3, n, i;
(3)Read n;
(4) i =1;
(5) if(i<=n); Yes go to (6)
No go to (10)
(6) t3 =t1+t2;
(7) t1 =t2;
(8) t2 =t3;
(9)print t3;
(10)Stop.
(1) Start
(2) define a, b, sum;
(3) Read a, b;
(4) Sum = a+b;
(5) print sum;
(6) Stop
(3) To read a year and find out whether it is leap year or not.
(1) Start
(2) Define year;
(3) Read year;
(4) If ((year%4==0&&year%100!=0)||(year%400==0));Yesgoto(5)
Nogoto(7)
(5) Print a year is leap year;
Binty, Brinda, Ami F.Y.BCA- (B)
(6) Go to (8)
(7) Print a year is not leap year;
(8) Stop.
(1) Start
(2) define a, b, c, Sum, Average;
(3) Read a, b, c;
(4) Sum = a + b + c;
(5) Average = sum/3;
(6) Print average
(7) Stop.
[Question-2(B)]
(1) To read n from the user and compute the sum and average of first n
numbers.
(2) To display the n sum of the series for n terms, where n is read from
the user and the series is given as
Sum=1+8+27+64+…
Binty, Brinda, Ami F.Y.BCA- (B)
[Question-3(A)]
Array Structure
Break Continue
[Question-3(B)]
int x=10,y=20,sum=0,val=0;
while(sum<20)
{
Y+=5;
If(y%2==0)
Sum=sum+x;
else
Val=val-10;
}
printf(“%d%d%d%d”,x,y,sum,val);
Output:-
x = 10
y = 40
Sum = 20
Val = -20
int comp(int,int);
void main()
{
int u=20,v=30,a,b;
a=comp(u,v);
Binty, Brinda, Ami F.Y.BCA- (B)
b=comp(a,comp(v,u));
printf(“%d%d\n”,a,b);
}
Output:-
10
20
-205040
5040
5040
Solution
#include<stdio.h>
#include<conio.h>
Void main()
{
Char ch;
printf(“enter the character”);
scanf(“%d”,ch); : scanf(“%c”,&ch);
If(ch=’a’||ch=’z’)
Printf(“Last or first alphabet); : printf(“Last or first alphabet”);
if isdigit(ch)
Then : Remove Then
Binty, Brinda, Ami F.Y.BCA- (B)
Printf(“Digit”);
}
Solution
#include<stdio.h>
void MAIN() : void main()
{
int a1,b1;
print(“enter 2 numbers”); : printf(“enter 2 numbers”);
scanf(“%f%s”,&a1,&b1); : scanf(“%d%d”,&a1,&b1);
printf(“%2d\n%2d”,a1,b1);
}
[Question-4(A)]
(1) Explain the following string functions with syntax and example.
Strcat(), Stecmp() and Strcpy().
Ans: -
(i)Strcat function:-
The strcat function joins two strings together. It takes the following
form:
Strcat(string1, string2);
Binty, Brinda, Ami F.Y.BCA- (B)
String1 and string2 are character arrays. When the function strcat
is executed, string2 is appended to string1. It does so by removing
the null character at the end of string1 and placing string2 from
there. The string at string2 remains unchanged. For example,
consider the following three strings:
Part 1= 0 1 2 3 4 5 6 7 8 9 0 1
V E R Y \0
Part 2= 0 1 2 3 4 5 6
G 0 0 D \0
Part 3= 0 1 2 3 4 5 6
B A D \0
Part 1= 0 1 2 3 4 5 6 7 8 9 0 1 2
V E R Y G 0 0 D \0
Part 2= 0 1 2 3 4 5 6
G 0 0 D \0
Strcat(part1,part3);
Part 1= 0 1 2 3 4 5 6 7 8 9 0 1 2
V E R Y B A D \0
Binty, Brinda, Ami F.Y.BCA- (B)
Part 3= 0 1 2 3 4 5 6
B A D \0
We must make sure that the size of string1 (to which string2 is
appended) is large enough to accommodate the final string.
Strcat(part1,”GOOD”);
Strcat(strcat(string1,string2),string3);
Is allowed and concatenates all the three strings together. There
results string is stored in string1.
Strcmp(string1,string2);
Strcmp(name1,name2);
Strcmp(name1,”John”);
Strcmp(“Rom”,”Ram”);
Binty, Brinda, Ami F.Y.BCA- (B)
Strcmp(“their”,”there”);
Will return a value of -9 which is the numeric difference between
ASCII “i” and ASCII “r”. That is “i” minus “r” in ASCII code is -9. If
the value is negative, string1 is alphabetically above string2.
Strcpy(string1,string2);
Strcpy(city,”Delhi”);
Will assign the contents of the string variable string2 to the string
variable city1. The size of the array city1 should be large enough to
receive the contents of city2.
(2) Explain singly linked list, doubly linked list and circular linked list.
Ans: - In other word we can say that An Array is a list refers to a set of
items organized sequentially.
One major problem with the array is that the size of an array must
be specified precisely at the beginning.
According to the process there are four main types of link list.
Advantages :-
Link list can grow or shrink in size during the execution of a
program.(but array can’t)
Link list can be made just as long as it required(Array has some fix
size at declare)
Link list does not waste memory space (Array can)
Link list provide very much flexibility to add, insert, delete node in
list(Array can’t)
Link list can access by reference (pointer) (Array doesn’t need)
Disadvantages :-
Arbitrary items accessing cumbersome and time consuming.
When we know the length of list it is better to use an array then
link list.
Little bit difficult to provide accessing by pointer.
(3) Explain the following file function with syntax and example.
Rewind(), fclose( ) and fopen( ).
Ans:- Rewind( fp ):
Rewind takes a file pointer and resets the position to the
start of the file.For examp;e the statement:
Binty, Brinda, Ami F.Y.BCA- (B)
Rewind( fp );
N=ftell( fp ):
Would assign to fp because the file position has been set the start of the file
by rewin.This function helps us in reading a file more than once.Without
having to close and open the file.
fclose( ):
A file must be closed as soon as all operations on it have been
completed. This ensures that all outstanding information associated with the
file is flushed out from the buffers and all links to the file are broken.It also
prevents any acidental misuse of the file. In case, there is a limit to the
number of files that can be kept open simultaneously, closing of unwanted
files might help open the required files.Another instance where we have to
close a file is when we this for us.It takes the following form:
.....
.....
FILE *p1, *p2;
p1 = fopen (" INPUT", "w");
P2 = fopen(" OUTPUT", "r");
.....
.....
fclose( p1 );
fclose( p2 );
.....
This program opens two files and closes them after all operations on them
are completed.Once a file is closed, its file pointer can be reused for another
file.
As a matter of fact all files are closed automatically whenever a program
terminates.However, closing a file as soon as you are done with it is a good
programming habit.
Binty, Brinda, Ami F.Y.BCA- (B)
fopen( ):
Where file _name and file _type are strings that representes the
name of the data file and the manner in which the data file will be utilized,
respectively.The name chosen for the file name must be consistent within the
rules for naming files, as determined by the computer's operating system.
The file_type must be one of the strings shown in the following table:
We can open and use a number of files at a time. This number however
Binty, Brinda, Ami F.Y.BCA- (B)
#define M 5
Will replace all occurrences of M with 5, starting from the line of definition
to the end of the program.However, a macro inside a string does not get
replaced. Consider the following two lines:
Total = M * value;
printf(" M = %d\n" , M);
total = 5 * value;
printf(" M = %d\n" , 5)
Notice that the strings "M=%d\n" is left unchanged.
A macro definition can include more than a simple constant value. It
can include expressions as well.Following are valid definitions:
#define D 45 – 42
#define A 78 + 32
Binty, Brinda, Ami F.Y.BCA- (B)
Correct results can be obtained by using parentheses around the strings as;
the token == in logical expressions. Similar is the case with the token &&.
Following are a few definitions that might be useful in building error free
and more readable programs:
#define EQUALS ==
#define AND &&
#define OR II
#define NOT_EQUAL !=
#define START main () {
#define END }
#define MOD %
#define BLANK LINE printf(“\n”);
#define INCREMENT ++
START
……..
……..
If(total EQUALS 240 AND average EQUALS 60)
INCREMENT count;
……..
…….
END
Notice that there is no space between the macro identifier and the left
parentheses.The identifiers f1, f2,… … .,fn are the formal macro arguments
that are analogous to the formal arguments in a function definition.
Binty, Brinda, Ami F.Y.BCA- (B)
PRINT(price * quantity);
Note that the actual paramaters are substituted for formal parameters in a
macro call, although they are within a string. This definition can be used for
printing integers and character strings as well.
Nesting of macros:
We can also use one macro in the definition of another macro. That is, macro
definitions may be nested. For instance, consider the following macro
definitions.
#define M 5
#define N M+1
#define SQUARE(x) ( (x) * (x) )
#define CUBE(x) (SQUARE (x) * (x) )
#define SIXTH (CUBE(x) * CUBE(x) )
The preprocessor expands each #define macro, until no more macros
appear in the text. For example, the last definition is expanded into
MAX(x, MAX(y,z) )
Undefining a Macro:
A define macro can be undefined, using the statement
#undef identifier
This is useful when we want to restrict the definition only to a particular part
of the program.
• Assignment operators
• Increment and decrement operators
• Conditional operators
• Bitwise operators
• Special operators
1. Arithmetic operators:-
Expression Values
A+B 13
a-b 7
A*B 30
A/B 3
A%b 1
2. Relational operators:
3. Logical operatoprs:
Operators Meaning
& AND
II OR
! NOT
Operands Results
Exp1 Exp2 Exp1&Exp2 Exp1 II Exp2
0 0 0 0
Binty, Brinda, Ami F.Y.BCA- (B)
0 Non-zero 0 1
Non-zero 0 0 1
Non-zero Non-zero 1 1
4. Assignment operators:
In addition to equal to (=) operator "C" also supports hand assignment
operators.
Identifier =Expression
a=a+1 a+=1
a=a-1 a- =1
a=a/(n-1) a/=(n-1)
a=a%10 a%=10
++&_ _
Examples:
++a & a++ (writting form)
m=5 m=5
y=+m y=++
In this case value of y and m will be six(6)
In this case value of y will be 5 and m will be 6
A prefix operator first adds one to the opernal & them the result
is assign to the variable on left.
A prefix operator first assigns a value to the variable in left &
than increment the opernal.
Binty, Brinda, Ami F.Y.BCA- (B)
6. Conditional operator:
Here if condition is evaluated as true then value of exp2 will be return and if
condition is evaluated as false then exp 3 will be return.
Example:
T=(I<0)? 0 : 100
If I variable value less then O then condition is evaluated as true
Y will be assigned with ) but if I variable value is greater then condition is
evaluated as false and 100 will be assign to variable T.
Example:
Printf("%d", (I<0) ? 0:100)
6. Bitwise operators:-
C has a distinction of supporting special operators known as
bitwise operators for manipulation of data at bit level.These operators are
used for testing the bits, or shifting them right or left.Bitwise operators may
not be applied to float or double.
Example:
Operators Meaning
& bitwise AND
I bitwise OR
^ Bitwise exlusive OR
Binty, Brinda, Ami F.Y.BCA- (B)
7. Special operators-
Eg:-int a[10]
size of (a); 20 bytes
Ans:-
• Nested of If…else statement:-
………….
If(sex is female)
{
if(balance>5000)
bonus=0.05*balance;
else
bonus=0.02*balance;
}
else
Binty, Brinda, Ami F.Y.BCA- (B)
{
bonus=0.02*balance;
}
balance=balance+bonus;
……………
……………
grade=”Second class”;
else if (marks>39)
grade=”Third division”;
else
grade=”fail”;
printf(“%s\n”,grade);
[Question-4(B)]
Ans: - When we know in advance exactly how many times the loop will be
executed, we use a counter controlled loop. This loop is called counter
controlled loop.
(4)What is prototyping?
Ans:-A function declaration is called as a function prototype or function
signature. So, it would be used to reduce the compiling time.
Ans:- If the operands are of different types, the lower type is automatically
converted to higher type and the result is of higher type. This automatic
conversion is known as implicit type conversions
Ans:-
#include<stdio.h>
#include<conio.h>
void main()
{
int num,sum=0;
printf(“Enter the number : ”);
scanf(“%d”,&num);
while(num>0)
{
sum=sum*10+num%10;
num=num\10;
}
If(sum==num)
Binty, Brinda, Ami F.Y.BCA- (B)
{
Printf(“the number is palindrome”);
}
Else
{
Printf(“the number is not palindrome”);
}
getch();
}
(2)Read a string and find out the following without using any string
function.
Ans:-
#include<stdio.h>
main()
{
int len=0;
clrscr();
char s[10];
printf(“Enter a string”);
scanf(“%[^\n]”,s);
while(s[len]!=’\0’)
{len++;}
printf(“Length : %d”,len);
}
Ans:-
#include<stdio.h>
#include<ctype.h>
main()
{
char s[40],ch;
int len=0,I,c=0;
while(s[len]!=’\0’)len++;
for(i=0;i<len;++i)
{
ch=toupper(s[i]);
if(ch==’A’||ch==’I’||ch==’O’||ch==’U’)c++;
}
printf(“Total count :”,c);
}
for(i=0;i<n;++i)
{
Scanf(“%d”,&num[i]);
If(num[i]>max)
{
Max=num[i];
}
}
Printf(“Maximum=%d”,max);
getch();
}
#include<stdio.h>
#include<conio.h>
struct student
{
char name[20];
float basic;
float da;
float total;
Binty, Brinda, Ami F.Y.BCA- (B)
}st[10];
void main()
{
int i;
for(i=1;i<=10;i++)
{
printf("Emploee name:");
scanf("%s",&st[i].name);
printf("employee basic:");
scanf("%f",&st[i].basic);
}
for(i=1;i<=10;i++)
{
st[i].da=0.9*st[i].basic;
st[i].total=st[i].basic+st[i].da;
}
printf("********************************************");
printf("emp_name\t emp_basic\t emp_da\t emp_total\n");
for(i=1;i<=10;i++)
{
printf("%s\t %f\t %f\t
%f\n",st[i].name,st[i].basic,st[i].da,st[i].total);
}
getch();
}
Ans:-
#include<stdio.h>
#include<conio.h>
Void main()
{
Int i,j,n=4;
For(i=1;i<=n;++i)
{
For(j=1;j<=I;j++)
{
Printf(“%d”,i);
}
Printf(“\n”);
}
}
Ans:-
#include<stdio.h>
#include<conio.h>
Void main()
{
int n,i,sum=0,k=1;
printf(“Enter n : ”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
K=k*I;
Sum=sum+k
}
Printf(“sum=%d”,sum);
Binty, Brinda, Ami F.Y.BCA- (B)
getch();
}
[Question-5(B)]
(1)A data structure, which allows storing multiple items of the same
data type:- Structure
(2) A derived data type, which allows storing the memory addresses:-
Pointer.