2018-2019 Cse
2018-2019 Cse
ANS: The source programming language is either a high level programming language or assembly
language. The target language in almost all cases is machine language which is in binary. A translator is a
program that converts source code into object code. Generally, there are three types of translator:
compilers , interpreters and assemblers.
Assembler:
1. Translate low level language into machine code.
2. Written for particular hardware.
3. One instruction translate to many instruction .(one to one).
4. Translates entire program before running.
5. They produce object code.
Compiler:
1. Translate high level language into machine language.
2. Written for particular language.
3. One instruction translates to many instruction.(one to many)
4. Translates entire program before running.
Interpreter:
1. Translate high level language to machine code.
2. Written for particular language.
3. One instruction translates to many instructions.
4. Translates program instruction by instruction until an either completed or error detected.
5. It does not produce an object code.
1.(b). What are basic data types that c supports ? What is identifier in c? …………………………………(1.75)
In C, the names of variables, functions, labels, and various other user-defined items are called
identifiers. The length of these identifiers can vary from one to several characters. The first character
must be a letter or an underscore, and subsequent characters must be either letters, digits, or
underscores. Here are some correct and incorrect identifier names:
Correct Incorrect
count 1count
test23 hi!there
high_balance high . . . balance
1.(c). What is operator ? What are the different types of operators used in c programming?
…………….(2)
ANS: An operator is a symbol that tells the computer to perform certain mathematical or logical
manipulations. Operator are used in programs to manipulate data and variables. They usually
form a part of a mathematical or logical expressions.
1.(d). Evaluate the value of z from the following expression if x=19 and y=5;
ANS:
#include<stdio.h>
#include<math.h>
int main()
int x = 19,y = 5, z;
z = y%x;
printf("z = %d\n",z);
z = fabs(y-x);
printf("z = %d\n",z);
return 0;}
Z=5
Z = 14
−𝒃+√𝒂𝟐 −𝟒𝒂𝒄
2.(a). Convert the following expression to c expression: x= …………………………………(1)
ANS:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
float a, b, c, x, z;
float root_part;
z = a*a - 4*a*c;
if(z>0){
x = -b + root_part;
printf("%f",x);
else
getch();
2.(b). Find how many times ‘var’ will be printed, and explain why:
#include<stdio.h>
int main()
int var=1;
While(var <= 2)
Printf(“%d”,var);
} ………………………………………………………(1)
ANS: ‘var’ will be printed infinite times. Because it is a infinite loop. The infinite loop happens when the
condition in the while loop always evaluates to true. This can happen when the variables within the loop aren't
updated correctly, or aren't updated at all. ... The condition evaluates to true, and the loop begins an infinite run.
2.(c). Write a c program to convert specified days into years, weeks and days.(ignore leap year)
…………………..(3.50)
ANS:
#include<stdio.h>
int main()
printf("Enter days\n");
scanf("%d", &days);
years = days/365;
weeks = (days%365)/7;
days = days-((years*365)+(weeks*7));
2.(d). Write a C program to determine whether a number is odd or even, and print the
message”NUMBER IS EVEN” or “NUMBER IS ODD” accordingly. ………………………………(3.25)
ANS:
#include<stdio.h>
#include<stdlib.h>
int main()
int number;
scanf("%d", &number);
if((number % 2) == 0){
else{
ANS: Switch is a multiway decision statement. The switch statement tests the value of a given
variable(or expression) against a list of case values and when a match is found, a block of statements
associated with that case is executed. The general form of the switch statement is as shown below:
The expression is an integer expression or characters. Value-1,value-2 ……are constants or constant
expressions and are known as case levels. Each of these values should be unique within a switch
statements.
When the switch the executed, the value of the expression is successfully compared against the values
value-1,value-2… if a case is found whose value matches with the value of the expression, then the block
of statements that follows the case executed.
The break statement at the end of each block signals the end of a particular case and causes an exit from
the switch statement, transferring the control to the statement-x following the switch.
3.(b). Write a program using a do……..while loop to calculate and print the first m Fibonacci numbers.
…………………..(3.0)
ANS:
#include<stdio.h>
void main()
scanf("%d",&m);
i = 0;
do {
if(i<=1)
printf(" %d ",i);
else
num1 = num2;
num2 = fib;}
i++;
while(i<= m);
ANS: The if…………….else statement is an extension of the simple if statement. In C it is used to perform the operations based
on some specific condition. The operations specified in if block are executed if and only if the given condition is true. If the test
expression is true, then the true-block statement(s), immediately following the if statements are executed.; otherwise, the false-block
statement(s) are executed. In either case, either true-block or false-block will be executed, not both.
3.(d). Write a program to print the following output using for loops.
……………………………………….(2.75)
*****
****
***
**
ANS:
#include<stdio.h>
int main()
int i, j;
for(j=5 ; j>=I ; j- -)
printf(" * ");
printf("\n");
4.(a). What is an array? Explain with example how an array can be passed to a function as an
argument. …………….(3)
ANS: An array is a sequenced collection of related data items that share a common name. It is simply a
grouping of like type data.
An array is a collection of variables of the same type that are referred to through a common name. A
specific element in an array is accessed by an index. In C, all arrays consist of contiguous memory
locations. The lowest address corresponds to the first element and the highest address to the last
element. Arrays can have from one to several dimensions. The most common array is the string, which is
simply an array of characters terminated by a null.
C does not permit to pass an entire array as an argument to a function. It permits to pass a pointer to an
array by specifying array’s name without an index. Its only pass the address of the first array not all the
arrays address. For example, the following program fragment passes the address of i to func():
int main(void)
int i[10];
… … … …
… … … …
*……………………….. *
Or,
*………………………....*
The first declaration actually uses a pointer. The second employs the standard array declaration.
4.(b). Write a program to find the average of n (n < 10) numbers using arrays.
ANS:
4.(c). What is pointer? Describe how pointer is declared and initialized? …………………………..(2)
ANS: A pointer is a variable that holds a memory address. This address is the location of another object
(typically another variable) in memory. If one variable contains the address of another variable, the first
variable is said to point to the second. Pointers can be used to access and manipulate data stored in the
memory.
data_type *pt_name;
ANS: The process of allocating memory at run time is known as dynamic memory allocation. Dynamic
data structure provide flexibility in adding, deleting or rearranging data items at run time. Dynamic
memory management techniques permit us to allocate additional memory space or to release
unwanted space at run time.
A block of memory may be allocated using the function malloc. The malloc function reserves a block of
memory of specified size and returns a pointer of type void. It takes the following form
5.(a). Define function used in C. Describe the necessity of user defined function.
5.(c). What is recursion? Write a program to calculate the factorial of a number ‘n’.
ANS: Recursion is the process which comes into existence when a function calls a copy of itself to
work on a smaller problem.
#include<stdio.h>
6.(a). Define string. What are the common operations performed on string?
strncat() Appends a given number of characters from one string to the end
of another.
int main () {
char str[50];
return(0);
}
ANS: The strcmp() compares two strings character by character. If the strings are equal, the function
returns 0.
A structure creates a data type that can be used to group items of possibly different
types into a single type. But Array refers to a collection consisting of elements of homogeneous
data type.
7.(b). How can you initialize a structure?
ANS: struct Point
int x, y;
};
int main()
p1.x = 10;
p1.y = 20;
return 0;
Example:
stuct emp{
int a;
char name[30];
struct allowance{
int num;
char address[30];
}a;
}e;
8.(a). What is object oriented programming ? Write down the features of object oriented
programming.
• Encapsulation
• Inheritance
• Polymorphism.
ANS: