NEB Class 12 · Exam intelligence
From 6 NEB Class 12 past papers: the chapters that keep coming back and their most important questions, each with a solved model answer. No guarantees; study the whole syllabus.
From the most-tested chapters first, each with a solved model answer.
(a) Describe the switch statement with example.
(b) Demonstrate the FOR loop with example.
(a) The switch statement. switch is a multiway selection statement in C. It evaluates an integer or character expression once and transfers control to the case label whose constant matches that value, which is clearer than a long chain o...
What is array ? Write a program to input any 10 numbers in an array and display it.
An array is a collection of a fixed number of elements of the same data type stored in consecutive memory locations under a single name. Each element is reached by an index, and in C the index always starts at 0, so an array declared as ...
(a) Define 'function' in C. Write a program to calculate the factorial of given number using function.
A function in C is a self contained block of statements with a name, which performs one well defined task and can be called from anywhere in the program. It may take values through its parameters and may send a value back with return. A ...
Why do you use structure ? Write a program to input teacher id, name address and subject of 10 teachers and display them properly using structure.
A structure is used because an array can hold only values of one type, while a real world record is made of several different types. A teacher has a numeric id, a name, an address and a subject, that is an int and three strings, and no s...
What is pointer ? write a program to enter the name, mobile and post of employee and write it in file " worker.dat" in C program.
A pointer is a variable that holds the memory address of another variable rather than a value of its own. If p stores the address of an integer b, then p is declared int p; and set with p = &b;, where & is the address of operator. The va...
Write a program which reads names of 100 students and sort them in alphabetial order. [10]
A list of names can be stored as a two dimensional character array, one row per student, and then arranged into order with a simple exchange (bubble) sort that compares adjacent names with strcmp() and swaps them with strcpy() whenever t...
Describe 'Sequence', 'Selection' and 'Loop' with flowchart. Write a program to check if a number is odd or even. [6+4]
Sequence, selection and loop are the three basic control structures used to build the logic of any program. Sequence means statements are executed strictly one after another in the order they are written, with no branching. Its flowchart...
What is pointer ? Describe the benefits of pointer with examples. [4+6]
A pointer is a variable that does not store an ordinary value but stores the memory address of another variable. It is declared using the operator, for example int p; declares p as a pointer to an integer, and p = &x; makes p hold the ad...
What is an array ? Write a program which finds multiplication of two matrices (3 X 3) [2+8]
An array is a collection of elements of the same data type stored in contiguous memory locations and referred to by a single name with an index, for example int a[3][3] is a two dimensional array (matrix) of 9 integers, accessed as a[i][...
Write a program which reads name, roll-number and age from a file named "student.dat" and display them. [10]
A structure is the natural way to group a student's name, roll number and age together, and the standard C file functions fopen(), fprintf() and fscanf() can then be used to write this data to student.dat and read it back. The file is fi...
Write a C program that reads the account_number, name and address of ten customers from users and displays the account_number, name and address of these customers using Array and structure.
#include <stdio.h>
struct Customer {
int account_number;
char name[30];
char address[50];
};
int main() {
struct Customer c[10];
int i;
for (i = 0; i < 10; i++) {
printf("Enter account number, name and address of customer %d: ", i + 1);
scanf("%d %s %s", &c[i].account_number, c[i].name, c[i].address);
}
printf("\nAccount Number\tName\tAddress\n");
for (i = 0; i < 10; i++)
printf("%d\t%s\t%s\n", c[i].account_number, c[i].name, c[i].address);
return 0;
}
The structure Customer groups the account_number, name and address of one customer, and the array c[10] stores the records of all ten customers. The first for loop reads these three fields for each customer from the user, and the second for loop then prints the account number, name and address of every customer stored in the array.
What are the components of a function of C ? Describe the Call - by - value and Call - by - reference and passing the function parameters.
Components of a function in C:
int add(int, int);.{ }) that carry out the task.add(3, 4);.return sum;.Call by value: in this method, a copy of the actual argument's value is passed to the function's parameter. Because the function works only on this copy, any change made to the parameter inside the function does not affect the original variable in the calling function.
void increment(int x) {
x = x + 1;
}
Calling increment(a) does not change a in the caller, since x is only a local copy.
Call by reference: in this method, the address of the actual argument is passed (using a pointer), so the function receives a pointer to the original variable. Any change made through this pointer inside the function directly modifies the original variable in the calling function.
void increment(int *x) {
*x = *x + 1;
}
Calling increment(&a) does change a in the caller, because x holds the address of a and *x dereferences it to modify the original value directly.
Write a C program that uses structures to represent details of five books (title, author, publisher and price) and prints them out.
The structure Book groups together a book's title, author, publisher and price as a single record, and the array b[5] stores five such records. The first for loop reads all four fields of each book from the user, and the second for loop ...
Discuss the concept of binary file handling in C programming and explain how putw ( ) and getw ( ) functions facilitate binary input/output operations. Give examples.
Binary file handling in C means storing data in a file exactly as it is represented in memory (as raw bytes), rather than converting it to readable text as fprintf()/fscanf() do. Binary files are opened with modes such as "wb" (write bin...
Write the advantage of pointer. Write a C-program to enter the radius of a football and find the area of football by using user defined function.
Advantages of pointer: pointers allow a function to directly access and modify the caller's variables (call by reference), let a program work efficiently with arrays and strings without copying them, enable dynamic memory allocation at r...
Define the structure. Write a C-program using structure to input staff id, name and the salary of 50 staffs. Display staff id, name and salary of those staff whose salary range from 25 thousand to 40 thousand.
A structure in C is a user defined data type that groups related variables of possibly different data types (such as an id, a name and a salary) under one name, so that they can be treated and passed around as a single unit.
#include <stdio.h>
struct Staff {
int id;
char name[30];
float salary;
};
int main() {
struct Staff s[50];
int i;
for (i = 0; i < 50; i++) {
printf("Enter id, name and salary of staff %d: ", i + 1);
scanf("%d %s %f", &s[i].id, s[i].name, &s[i].salary);
}
printf("\nStaff with salary between 25000 and 40000:\n");
printf("ID\tName\tSalary\n");
for (i = 0; i < 50; i++) {
if (s[i].salary >= 25000 && s[i].salary <= 40000)
printf("%d\t%s\t%.2f\n", s[i].id, s[i].name, s[i].salary);
}
return 0;
}
The structure Staff stores the id, name and salary of one staff member, and the array s[50] holds the records of all 50 staff. After all the records are read in the first loop, the second loop checks each staff member's salary and prints only the id, name and salary of those whose salary lies between 25,000 and 40,000.
What is structure ? Write a program to input roll, name and age of 5 students and display them properly using structure.
A structure in C is a user defined data type that groups together variables of different data types under a single name, so that related information (such as a student's roll number, name and age) can be handled as one unit.
#include <stdio.h>
struct Student {
int roll;
char name[30];
int age;
};
int main() {
struct Student s[5];
int i;
for (i = 0; i < 5; i++) {
printf("Enter roll, name and age of student %d: ", i + 1);
scanf("%d %s %d", &s[i].roll, s[i].name, &s[i].age);
}
printf("\nRoll\tName\tAge\n");
for (i = 0; i < 5; i++)
printf("%d\t%s\t%d\n", s[i].roll, s[i].name, s[i].age);
return 0;
}
The structure Student bundles roll, name and age together, and the array s[5] holds five such records. The first loop reads each student's data into s[i].roll, s[i].name and s[i].age, and the second loop prints those same fields for all five students in a tabular form.
Write a C program to enter ID, employee_name, and post of the employee and store them in a data file named "emp.txt". Display each record on the screen in an appropriate format.
Each employee's ID, name and post can be grouped into a structure, written to the text file emp.txt with fprintf(), and then read back and displayed with fscanf(). The file emp.txt is opened in write mode and each entered record is appen...
What are the logical operators in C ? Explain with an example.
Logical operators in C combine or invert conditions and yield a result that is either 1 for true or 0 for false. They are used to build a compound condition out of simpler relational tests, typically inside an if statement or a loop. C provides three.
Logical AND (&&) gives true only when both its operands are true. (a > 0 && b > 0) is true only if both numbers are positive.
Logical OR (||) gives true when at least one of its operands is true, and false only when both are false. (ch == 'y' || ch == 'Y') is true for either case of the letter.
Logical NOT (!) is a unary operator that reverses the truth of its operand, so !(a == b) is true exactly when a is not equal to b.
Their truth table, with any non zero value counting as true:
| a | b | a && b | a || b | !a |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 |
An important property is short circuit evaluation: in && the second operand is not evaluated at all if the first is false, and in || it is not evaluated if the first is true, since the answer is already settled.
#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year.\n", year);
return 0;
}
The condition uses all the ideas together. A year is a leap year if it is divisible by 4 and not by 100, which is the first bracket joined by &&, or if it is divisible by 400, which is the second bracket joined by ||. For 2000 the first bracket is false (2000 is divisible by 100) but the second is true, so the whole condition is true. For 1900 both brackets are false and the year is not a leap year. For 2024 the first bracket is true, and because || short circuits, the second is never tested.
Describe "Operators" which are used in C-programming. [5]
An operator in C is a symbol that tells the compiler to perform a specific mathematical, relational or logical operation on one or more operands. The main categories are: - Arithmetic operators (+, -, , /, %) perform addition, subtractio...
Which of the following is true about FILE *fpt ? A) FILE is a keyword in c for representing files and fpt is a variable of FILE type B) FILE is a buffered Stream C) FILE is a Stream D) FILE is a structure and fpt is a pointer to the structure of FILE type.
The correct option is D. In C, FILE is actually a structure type (defined in stdio.h) that holds information about an open file such as its position and buffer, and a file pointer such as fpt is declared as FILE fpt to point to (that is,...
What is the output of C program? void main(){ int b=25; int *p; p=&b; printf("%d %d", &b, p);}
The correct option is B) 1234 1234 (taking the address of b to be 1234, as marked in the question). Since p = &b;, the pointer p is assigned the same address as &b, so printf("%d %d", &b, p) prints the same address value twice.
Write any three differences between DDL and DML. Give examples of each.
DDL (Data Definition Language) and DML (Data Manipulation Language) are both subsets of SQL, but they serve different purposes.
| Basis | DDL | DML |
|---|---|---|
| Purpose | Defines and changes the structure of database objects | Manipulates the actual data stored inside the tables |
| Commands | CREATE, ALTER, DROP, TRUNCATE | SELECT, INSERT, UPDATE, DELETE |
| Effect on data | Does not directly work with row level data, only the schema | Directly adds, changes, retrieves or removes rows of data |
| Transaction control | Changes are usually auto-committed and cannot be rolled back in many systems | Changes can typically be rolled back before being committed |
Example of DDL:
CREATE TABLE student (regno INTEGER, name CHARACTER(25));
Example of DML:
INSERT INTO student VALUES (101, 'Ram');
What is normalization ? Explain 2NF and 3NF.
Normalization is the process of organizing the tables and columns of a relational database so as to minimize data redundancy and avoid update, insertion and deletion anomalies, usually by progressively breaking large tables into smaller, well structured related tables.
Second Normal Form (2NF): a table is in 2NF when it is already in 1NF (all attributes atomic, no repeating groups) and every non key attribute depends on the whole primary key, not on just part of it. This matters mainly for tables with a composite key; if a non key column depends on only part of the composite key, that partial dependency is removed by splitting the table.
Third Normal Form (3NF): a table is in 3NF when it is already in 2NF and, in addition, no non key attribute depends on another non key attribute (that is, there is no transitive dependency). For example, if a table stores StudentID, DepartmentID, DepartmentName, then DepartmentName depends on DepartmentID, which itself is not the primary key, so this is a transitive dependency; achieving 3NF means moving DepartmentName into its own Department table.
In short, 2NF removes partial dependency on a composite key, while 3NF goes further and removes dependency of one non key column on another non key column.
Write JavaScript code to input any three numbers and find the smallest number among them.
function findSmallest(a, b, c) {
let smallest = a;
if (b < smallest) {
smallest = b;
}
if (c < smallest) {
smallest = c;
}
return smallest;
}
let x = 12, y = 7, z = 9;
console.log("The smallest number is " + findSmallest(x, y, z));
The function starts by assuming a is the smallest, then checks b against the current smallest and updates it if b is smaller, and finally does the same check with c. After both comparisons, smallest holds the least of the three values. For x = 12, y = 7, z = 9 the code prints "The smallest number is 7".
Study every chapter with notes and solved questions
Open Computer Science notes and questions