Methodology and Programming in C, Semester 1(2021-24), Model examination, June 2022
SAINTGITS
COLLEGE OF APPLIED SCIENCES
PATHAMUTTOM, KOTTAYAM
Model Examination, JUNE
/ JULY 2022
Department of Computer Applications, Semester 1
CS1CRT02 - METHODOLOGY OF PROGRAMMING AND C
LANGUAGE
Total : 80 marks Time: 3 hours
Section A
Answer any 6 questions. Each question carries 3 marks.
(Write in not less than a paragraph)
1.
List out
the characteristics of a good programming language.
Characteristics of
a programming Language –
· A programming language must be simple, easy to
learn and use, have good readability, and be human recognizable.
· Abstraction is a must-have Characteristics for a
programming language in which the ability to define the complex structure and
then its degree of usability comes.
· A portable programming language is always
preferred.
· Programming language’s efficiency must be high so
that it can be easily converted into a machine code and executed consumes
little space in memory.
· A programming language should be well structured
and documented so that it is suitable for application development.
· Necessary tools for the development, debugging,
testing, maintenance of a program must be provided by a programming language.
· A programming language should provide a single
environment known as Integrated Development Environment(IDE).
· A programming language must be consistent in terms
of syntax and semantics.
2.
Create an algorithm to find the reverse of a number.
1.
Ask the user to enter any number.
2.
Declare and initialize another variable reversed with 0, where
reversed an integer variable.
3.
Get the last digit of the given number by performing the modulo
division (%) and store the value in last_digit variable, last_digit= number %
10.
4.
Multiply reversed by 10 and add last_digit, like reversed =
reversed*10 + last_digit.
5.
Divide numbered by 10, like numbered/10.
6.
Repeat the steps 3 to 5 till numbered is not equal to (or greater
than) zero.
3.
How is a C program structured?
A 'C' program
is divided into six sections: Documentation, Link, Definition, Global
Declaration, Main () Function, Subprograms. While the main section is
compulsory, the rest are optional in the structure of the C program.
4.
Explain C character set.
The C
character set consists of upper and lowercase alphabets,
digits, special characters and white spaces.
5.
Define the term 'type casting'.
Typecasting is a method in C language
of converting one data type to another.
There are two types of typecasting.
1.Implicit Type casting − This conversion is done by the compiler. When more than one data
type of variables is used in an expression, the compiler converts data types to
avoid loss of data.
2.Explicit Type casting − This conversion is done by user. This is also known as typecasting.
Data type is converted into another data type forcefully by the user.
6. What is
dynamic initialization?
Dynamic Initialization: Here, the
variable is assigned a value at the run time. The value of this variable can be
altered every time the program is being run.
7.
What is a loop?
Loops in C programming language is a
conditional concept used for consecutively executing a line or a block of code over and
over again until it reaches the value desired by the programmer. In C programming,
there are three types of loops, namely For Loop, While Loop and Do While Loop.
8.
Explain formatted functions in C?
Formatted I/O functions allow to supply input or
display output in user desired format. printf() and scanf() are examples for
formatted input and output functions.
9. What is meant by wild pointer?
Wild pointers are different from pointers
i.e. they also store the memory
addresses but point the unallocated memory or data value which has been
deallocated. Such pointers are known as wild pointers. A pointer behaves
like a wild pointer when it is declared but not initialized.
10.
What is user defined function?
User-defined
functions are a block of code
written by the user to perform a specific action. A user-defined
function has a return type, a function name, parameters, and body of the
function. Function can be called using the unique name of the function followed
by function parameters passed inside round brackets ().
11.
Compare Union and Structure in C
12. Define a) malloc b) calloc.
malloc () allocates a memory
block of given size (in bytes) and returns a pointer to the beginning of the
block. malloc () doesn’t initialize the allocated memory. If you try to read
from the allocated memory without first initializing it, then you will invoke undefined behaviour,
which will usually mean the values you read will be garbage.
calloc () allocates the memory and also
initializes every byte in the allocated memory to 0. If you try to read the
value of the allocated memory without initializing it, you’ll get 0 as it has
already been initialized to 0 by calloc ().
(6 x 3 = 18 Marks)
Section B
Answer any 4 questions. Each question carries 8 marks.
(Write in not less than 2 pages)
13.Explain Assembler and Compiler
Compiler :
The language processor that reads the complete source program written in
high-level language as a whole in one go and translates it into an equivalent
program in machine language is called a Compiler. Example: C, C++, C#,
Java.
(4 marks)
Assembler :
The Assembler is used to translate the program
written in Assembly language into machine code. The source program is an input
of an assembler that contains assembly language instructions. The output
generated by the assembler is the object code or machine code understandable by
the computer.
(4
marks)
14.Explain the various
control structures used in a programming language.
Control
Structures are just a
way to specify flow of control in programs. Any algorithm or program can be
more clear and understood if they use self-contained modules called as logic or
control structures. It basically analyses and chooses in which direction a
program flows based on certain parameters or conditions. There are three basic
types of logic, or flow of control, known as: ( 2 marks)
1.
Sequence logic,
or sequential flow
2.
Selection logic,
or conditional flow
3.
Iteration logic,
or repetitive flow
(2 marks each)
15.Explain various bitwise operators in C
Binary AND Operator, Binary OR Operator, Binary XOR Operator, Binary Left Shift
Operator, Binary Right Shift Operator.
(any
4 operators-2 marks each)
16.Distinguish break and continue statements with the help of
examples.
BREAK |
CONTINUE |
It terminates the execution of the
remaining iteration of the loop. |
It terminates only the current
iteration of the loop. |
break resumes the control of the
program to the end of loop enclosing that 'break'. |
continue resumes the control of the
program to the next iteration of that loop enclosing continue. |
It causes early termination of a
loop. |
It causes early execution of the
next iteration. |
break stops the continuation of the
loop. |
continuation of loop. continue do
not stop the continuation of the loop, it only stops the current iteration. |
the break can be used with switch,
label. |
continue cannot be executed with
switch and labels. |
(any
4 differences-2 marks each)
17.Given are the marks of three subjects. Write a C program to display
the student's grade ( A - above90%, B -
above 60%, C - above 40%) using else if ladder.
#include <stdio.h>
int main(void){
int num;
printf("Enter your mark ");
scanf("%d",&num);
printf(" You entered %d", num); // printing outputs
if(num
>= 80){
printf("
You got A grade"); // printing outputs
}
else
if ( num >=60){ // Note the space between else & if
printf("
You got B grade");
}
else
if ( num >=40){
printf("
You got C grade");
}
else
if ( num < 40){
printf("
You Failed in this exam");
}
return 0;
}
18. Write a C program to find the number of vowels in a string.
#include <stdio.h>
int main()
{
int c = 0, count = 0;
char s[1000];
printf("Input a
string\n");
gets(s);
while (s[c] != '\0') {
if (s[c] == 'a' || s[c]
== 'A' || s[c] == 'e' || s[c] == 'E' || s[c] == 'i' || s[c] == 'I' || s[c]
=='o' || s[c]=='O' || s[c] == 'u' || s[c] == 'U')
count++;
c++;
}
printf("Number of
vowels in the string: %d", count);
return 0;
}
19. Explain how to pass
array as argument to function with example.
To pass an entire
array to a function, only the name
of the array is passed as an argument. result = calculate_Sum(num);
Explanation-4 marks+example-4 marks
20. Differentiate between
call by value and call by reference with the help of an example.
·
In Call by value method original
value is not modified whereas, in Call by reference method, the original value
is modified.
·
In Call by value, a copy of the
variable is passed whereas in Call by reference, a variable itself is passed.
·
In Call by value, actual and formal
arguments will be created in different memory locations whereas in Call by
reference, actual and formal arguments will be created in the same memory location.
·
Call by value is the default method
in programming languages like C++, PHP, Visual Basic NET, and C# whereas Call
by reference is supported only Java language.
·
Call by Value, variables are passed
using a straightforward method whereas Call by Reference, pointers are required
to store the address of variables.
(any
4 key differences-2 marks each)
21. Write a program to find
the sum of n numbers using recursion.
#include <stdio.h>
int addNumbers(int n);
int main() {
int num;
printf("Enter a positive
integer: ");
scanf("%d", &num);
printf("Sum = %d",
addNumbers(num));
return 0;
}
int addNumbers(int n) {
if (n != 0)
return n + addNumbers(n - 1);
else
return n;
}
(4 x 8 = 32 Marks)
Section C
Answer up to 3 questions carrying 15 marks each. However, total marks
for this section should not exceed 30 marks. Marks scored over 30 will be
ignored
22. Write an essay about
the various types of programming languages with its advantages and
disadvantages.
A programming language is a set of symbols and rules for instructing a
computer to perform specific tasks. The programmers have to follow all the
specified rules before writing program using programming language. The user has
to communicate with the computer using language which it can understand.
Types of programming language
Machine language (5 marks)
Assembly language (5 marks)
High level language (5 marks)
23.
Explain different tokens in C language.
The individual elements of a program are
called Tokens. In a C program, a number of individual units or
elements occur. These elements are called C Tokens. In the C
language, the following 6 types of tokens are available:
- Identifiers
- Keywords
- Constants
- Operators
- Special Characters
- Strings
24. a) What is an array?
Explain single dimensional array b) Write a C program to insert an item into a
given position in an array.
An array is
a collection of items stored at contiguous memory locations.
Approach:
(Definition – 1mark, single dimensional
array-2 marks, program -5 marks)
25. Explain different
storage classes in C with example.
Storage classes in C are used to determine the lifetime, visibility,
memory location, and initial value of a variable. There are four types of
storage classes in C
o Automatic
o External
o Static
o Register (definition-1mark, types + example-14 marks)
(Maximum 30 Marks)
[Scan
QR code for Answer Key]
Comments
Post a Comment