Que & Ans CS First Year
Que & Ans CS First Year
Q. 1. List and explain the functions of various parts of computer hardware and
software.
Ans: Computer Hardware:
1. Central Processing Unit (CPU): The CPU is often referred to as the brain of the computer. It
performs most of the calculations and executes instructions of a computer program.
2. Random Access Memory (RAM): RAM is a type of volatile memory that provides temporary
storage for data and instructions that are currently being used by the CPU. It allows for quick access
to data, which improves overall system performance.
3. Hard Disk Drive (HDD) or Solid State Drive (SSD): HDDs and SSDs are storage devices used to
store data and software permanently. HDDs use spinning disks and magnetic heads to read and write
data, while SSDs use flash memory. They provide long-term storage for files and programs.
4. Motherboard: The motherboard is a circuit board that connects all the components of a computer
together. It provides communication between various hardware components, such as the CPU, RAM,
storage devices, and peripherals.
5. Graphics Processing Unit (GPU): The GPU is responsible for rendering images, videos, and
animations. It specializes in performing complex mathematical calculations required for graphics
processing and accelerates tasks related to visual content.
6. Power Supply Unit (PSU): The PSU converts AC power from an electrical outlet into DC power
that is required by the computer components. It supplies power to all the hardware components of the
computer.
7. Input and Output Devices: Input devices, such as keyboards and mice, allow users to provide
commands and data to the computer. Output devices, such as monitors and printers, display or
produce the results of computer processing.
Computer Software:
1. Operating System (OS): The OS is the fundamental software that manages computer hardware and
provides a user interface for interacting with the system. It handles tasks like memory management,
file management, and hardware device control.
2. Application Software: Application software refers to programs that perform specific tasks for users.
Examples include word processors, web browsers, photo editors, and video players. They are
designed to fulfill specific needs and enhance productivity or entertainment.
3. Device Drivers: Device drivers are software components that allow the operating system to
communicate and interact with hardware devices. They provide an interface for the OS to control and
utilize the features of devices like printers, scanners, and network adapters.
4. Utilities: Utility software includes programs that perform various maintenance and optimization
tasks on a computer. Examples include antivirus software, disk cleanup tools, backup utilities, and
system diagnostic tools.
5. Programming Languages: Programming languages are used to write software applications and
computer programs. They provide a way for developers to write instructions and algorithms that the
computer can understand and execute.
6. Compiler and Interpreter: Compilers and interpreters are software tools that convert high-level
programming languages into machine code or execute code directly. Compilers translate the entire
program in advance, while interpreters execute the program line by line.
7. Libraries and Frameworks: Libraries and frameworks are collections of pre-written code that
provide reusable functions and features for software development. They help programmers save time
by providing ready-made solutions for common tasks and functionalities.
These are just some of the key components and functions of computer hardware and software. The
field of computer science and technology is vast, and there are many more specific components and
software tools with specialized functions.
Q. 2. Define algorithm and state properties of it? Write an algorithm and flowchart for
swapping two numbers.
Ans: Algorithm:-An algorithm is a step-by-step procedure or set of rules designed to solve a
specific problem or accomplish a particular task. It provides a clear and unambiguous sequence of
instructions that can be followed to solve a problem, often with the goal of achieving the desired
outcome efficiently and accurately.
Properties of an algorithm:
1. Clear and Unambiguous: Each step of the algorithm should be well-defined and easily understood
without any ambiguity.
2. Input and Output: An algorithm takes one or more inputs and produces an output that is related to
the problem it is solving.
3. Finiteness: An algorithm must terminate after a finite number of steps, meaning it should not run
indefinitely.
4. Well-Defined Steps: Each step of the algorithm must be precisely defined and executable.
5. Deterministic: An algorithm should produce the same result for the same input every time it is
executed.
6. Efficiency: An algorithm should be designed to solve the problem efficiently, using the least
amount of resources and time possible.
7. Correctness: An algorithm should produce the correct output for all valid inputs and handle all
possible scenarios.
Algorithm and Flowchart for swapping two numbers:
Algorithm:
1. Start
2. Read the values of variable A and B.
3. Set temporary variable TEMP to 0.
4. Assign the value of A to TEMP.
5. Assign the value of B to A.
6. Assign the value of TEMP to B.
7. Print the values of A and B, which are now swapped.
8. Stop
Flowchart:
Note: In the flowchart, the arrows represent the flow of control, and the rectangles represent processes
or assignments. The values of variables A and B are swapped by assigning them to temporary variable
TEMP.
Q3. What do you mean by ‘Program Development Cycle’? Explain the steps involved in
that.
Ans:
The Program Development Cycle, also known as the Software Development Life Cycle
(SDLC), is a process followed by software developers to design, develop, test, and maintain
software applications. It encompasses a set of steps that guide the development process from
conception to deployment and maintenance. The program development cycle typically
consists of the following steps:
1. Requirement Gathering: In this initial phase, the software requirements are collected from
stakeholders, clients, or end-users. The goal is to understand the problem or need that the
software application should address.
2. Analysis and Planning: In this phase, the gathered requirements are analyzed, and a
detailed plan is created. This includes defining the scope, objectives, constraints, and
functionality of the software. The team also determines the feasibility of the project in terms
of resources, time, and budget.
3. Design: In this phase, the software architecture and system design are created based on the
requirements. The design includes both the high-level structure (e.g., modules, components)
and the low-level details (e.g., algorithms, data structures) of the software application.
4. Implementation: In this phase, the actual coding or programming of the software is
performed. The developers write the code according to the design specifications using
programming languages, frameworks, and tools. The implementation phase involves creating
and integrating different modules and components.
5. Testing: Once the code is implemented, thorough testing is conducted to identify and fix
any defects, bugs, or errors. Various testing techniques such as unit testing, integration
testing, system testing, and acceptance testing are employed to ensure the software meets the
requirements and functions as intended.
6. Deployment: After successful testing, the software is deployed or released to the end-users
or clients. It involves installing the software on the target environment and making it
available for use. Deployment may also include user training, data migration, and system
configuration.
7. Maintenance: Once the software is deployed, it enters the maintenance phase. During this
phase, any issues, bugs, or enhancements reported by users are addressed. Regular updates,
bug fixes, and performance improvements may be carried out to ensure the software remains
functional and up-to-date.
It's important to note that the program development cycle is not a linear process, but rather an
iterative one. Feedback from each phase can lead to revisions in earlier steps, ensuring that
the software meets the desired requirements and quality standards. The cycle may repeat for
new features or versions of the software, and the maintenance phase can continue for the
entire lifecycle of the software application.
Q4. Explain the symbols in a flowchart. Draw a flowchart to find the largest among two
numbers.
Ans: Symbols in a flowchart:
1. Start/End: Represents the beginning and end points of a flowchart. It is usually depicted as a
rounded rectangle with the word "Start" or "End" inside.
2. Process: Represents a specific action or process performed in the flowchart. It can be any
operation, calculation, or task that needs to be executed. It is usually depicted as a rectangle
with rounded corners.
3. Input/Output: Represents the input or output of data in the flowchart. It is used to indicate
the exchange of information between the user and the program. Input is typically represented
as a parallelogram, and output is represented as a rectangle with rounded corners.
4. Decision: Represents a conditional or branching point in the flowchart. It is used to make
decisions based on specific conditions or criteria. It is usually depicted as a diamond shape,
with arrows flowing in different directions based on the decision outcomes.
6. Flow lines: It represents the exact sequence in which instructions are executed. Arrows are
used to represent the flow lines in a flowchart. The symbol given below is used for
representing the flow lines.
Explanation:
1. The flowchart begins with the "Start" symbol.
2. The values of two numbers, A and B, are inputted.
3. The "Largest" variable is initially set to A.
4. A decision is made to check if B is greater than A. If it is, the value of "Largest" is updated to B.
5. The flow continues to the "Print Largest" symbol, where the largest number is outputted.
6. Finally, the flowchart ends with the "End" symbol.
This flowchart determines the largest among two numbers and demonstrates the use of input, process,
decision, and output symbols commonly used in flowcharts.
Q5. What are the different data types in C.
Ans:- In the C programming language, there are several built-in data types that allow you to store
different kinds of values. The common data types in C are as follows:
2. Call by Reference
In call by reference method of parameter passing, the address of the actual parameters is
passed to the function as the formal parameters.
Both the actual and formal parameters refer to the same locations.
Any changes made inside the function are actually reflected in the actual parameters
of the caller.
Example of Call by Reference
The following C program is an example of call by reference method.
// C program to illustrate Call by Reference
#include <stdio.h>
// Function Prototype
void swapx(int*, int*);
// Main function
int main()
{
int a = 10, b = 20;
// Pass reference
swapx(&a, &b);
printf("Inside the Caller:\na = %d b = %d\n", a, b);
return 0;
}
// Function to swap two variables
// by references
void swapx(int* x, int* y)
{
int t;
t = *x;
*x = *y;
*y = t;
printf("Inside the Function:\nx = %d y = %d\n", *x, *y);
}
Output
Inside the Function:
x = 20 y = 10
Inside the Caller:
a = 20 b = 10
Thus actual values of a and b get changed after exchanging values of x and y.
10. Write a function power (a, b) to calculate the value of a raised to b.
Ans:-
#include<stdio.h>
#include<conio.h>
#include<math.h>
int power(int a, int b);
int main()
{
int a, b, res;
printf("Enter a: ");
scanf("%d", &a);
printf("Enter b: ");
scanf("%d", &b);
res = power(a, b);
printf("Result: %d", res);
}
int power(int a, int b)
{
int x;
x = pow(a, b);
return x;
}
Output:
Enter a: 2
Enter b: 3
Result: 8
11. A 5-digit positive integer is entered through the keyboard, write a recursive and a
non-recursive function to calculate sum of digits of the 5-digit number.
Ans:-
#include<stdio.h>
int rec_func(int num);
int non_rec_func(int num);
void main( )
{
int num, rec, non_rec;
printf("Enter an integer: ");
scanf("%d", &num);
rec = rec_func(num);
non_rec = non_rec_func(num);
printf("\n Calculate sum using recursion: %d",rec);
printf("\n Calculate sum without recursion: %d",non_rec);
}
int rec_func(int num)
{
if (num==0)
{
return 0;
}
return (num%10+rec_func(num/10));
}
int non_rec_func(int num)
{
int res, count=0;
while(num!=0)
{
res=num%10;
count += res; //count=count+res;
num = num/10;
}
return count;
}
Output:
Enter an integer: 12345
Calculate sum using recursion: 15
Calculate sum without recursion: 15
12. Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence. In
a Fibonacci sequence the sum of two successive terms gives the third term. Following
are the first few terms of the Fibonacci sequence: 1 1 2 3 5 8 13 21 34 55 89 ……
Ans:-
#include<stdio.h>
int fibo(int num);
void main()
{
int num,c=0,i;
printf("Enter number: ");
scanf("%d", &num);
printf("Fibonacci Series:\n");
for(i=1;i<=num;i++)
{
printf("%d\n", fibo(c));
c++;
}
}
int fibo(int num)
{
if(num==0)
{
return 0;
}
else if(num==1)
{
return 1;
}
//fibonacci = 1 1 2 3 5 8
// where n = (n-1) + (n-2)
else
{
return (fibo(num-1)+fibo(num-2));
}
}
Output:-
Enter number: 25
Fibonacci Series:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
13. What are structures? How structure elements are accessed and stored.
Ans:-
Structure:
In computer programming, a structure is a composite data type that allows you to group
together related data elements. It is often referred to as a "struct" in many programming
languages. Structures enable you to create custom data types by combining different types of
variables into a single unit.
The elements of a structure, also known as members or fields, can have different data types
such as integers, floating-point numbers, characters, arrays, or even other structures. Each
member within a structure has a unique name and occupies a specific memory location.
To access and store structure elements, you typically use dot notation in most programming
languages. Here's an example to illustrate the concept:
Program:
// Define a structure named "Person"
struct Person {
char name[50];
int age;
float height;
};
int main() {
// Declare a variable of type "Person"
struct Person person1;
// Access and store values in structure elements
strcpy(person1.name, "John Doe");
person1.age = 30;
person1.height = 1.75;
// Access and display structure elements
printf("Name: %s\n", person1.name);
printf("Age: %d\n", person1.age);
printf("Height: %.2f\n", person1.height);
return 0;
}
In the example above, we define a structure called "Person" with three members: `name`,
`age`, and `height`. We declare a variable `person1` of type `Person`. Using dot notation
(`person1.name`, `person1.age`, `person1.height`), we can access and store values in each
structure member.
The data within a structure is stored sequentially in memory, with each member taking up the
appropriate amount of memory based on its data type. The compiler ensures that each
member is properly aligned and accessible within the structure.
It's worth noting that the syntax and specific features related to structures may vary slightly
depending on the programming language you are using. However, the fundamental concept
of grouping related data elements remains consistent across different languages.
14. Create a structure to specify data on students given below : Roll number, Name,
Department, Course, Year of joining Assume that there are not more than 450 students
in the college.
1. Write a function to print names of all students who joined in a particular year.
2. Write a function to print the data of a student whose roll number is received by the
functions
Ans:-
#include<stdio.h>
#include<conio.h>
#include<Windows.h>
struct studata
{
int roll;
char name[50];
char depart[50];
char course[20];
int yoj;
}nos[450] = { 03, "Kishor", "IT", "B.tech", 2014,
10, "Mohammad Siraj Alam", "Computer Science", "B.Tech", 2014,
53, "Deepak", "Computer Applications", "BCA", 2013,
13, "Karan", "Mechanical", "Diploma", 2013,
1, "Aakash", "Tool and Die", "Diploma", 2012,
2, "Ramesh", "IT", "B.tech", 2014
};
void student_in_year(int year)
{
int i;
printf("\n\t\tYear of joining : %d\n\n", year);
for (i = 0; i <= 450; i++)
{
if (nos[i].yoj == year)
{
18. Write a C program to input any alphabet and check whether it is vowel or consonant.
Ans:- C program that takes an input alphabet from the user and checks whether it is a vowel
or a consonant:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch;
printf("Enter any Alphabet\n"); //input alphabet from user
scanf("%c",&ch);//store the Entered Alphabet in ch
switch(ch)
{
//check lower case vowel letters
case 'a':
printf("%c is a vowel",ch);
break;
case 'e':
printf("%c is a vowel",ch);
break;
case 'i':
printf("%c is a vowel",ch);
break;
case 'o':
printf("%c is a vowel",ch);
break;
case 'u':
printf("%c is a vowel",ch);
break;
//check upper case vowel letters
case 'A':
printf("%c is a vowel",ch);
break;
case 'E':
printf("%c is a vowel",ch);
break;
case 'I':
printf("%c is a vowel",ch);
break;
case 'O':
printf("%c is a vowel",ch);
break;
case 'U':
printf("%c is a vowel",ch);
break;
default:
printf("%c is a consonant",ch);
break;
}
getch();
return 0;
}
Approach
19. Write a C program to input month number and print number of days in that month.
Ans:- Certainly! Here's a C program that takes an input month number from the user and
prints the number of days in that month:
```c
#include <stdio.h>
int main() {
int month;
switch (month) {
case 1:
printf("January has 31 days.\n");
break;
case 2:
printf("February has 28 or 29 days.\n");
break;
case 3:
printf("March has 31 days.\n");
break;
case 4:
printf("April has 30 days.\n");
break;
case 5:
printf("May has 31 days.\n");
break;
case 6:
printf("June has 30 days.\n");
break;
case 7:
printf("July has 31 days.\n");
break;
case 8:
printf("August has 31 days.\n");
break;
case 9:
printf("September has 30 days.\n");
break;
case 10:
printf("October has 31 days.\n");
break;
case 11:
printf("November has 30 days.\n");
break;
case 12:
printf("December has 31 days.\n");
break;
default:
printf("Invalid month number.\n");
break;
}
return 0;
}
```
Explanation:
1. The program prompts the user to enter a month number between 1 and 12.
2. The `scanf` function is used to read the input month number and store it in the variable
`month`.
3. The program uses a switch case statement to check the value of the input month.
4. Cases 1, 3, 5, 7, 8, 10, and 12 are specified as months with 31 days, so if the input matches
any of these cases, the program displays the corresponding message.
5. Case 2 represents February, which can have either 28 or 29 days in a leap year. The
program displays the corresponding message for February.
6. Cases 4, 6, 9, and 11 are specified as months with 30 days, and the program displays the
corresponding message for these months.
7. If the input does not match any of the cases, the default case is executed, and the program
displays an "Invalid month number" message.
8. Finally, the program returns 0 to indicate successful execution.
This program allows the user to input a month number, and it then determines and displays
the number of days in that month.