



































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




































































---------------------------------------------------------------------------------------------------------------------------------------------------
1. List and explain the functions of various parts of computer hardware and software. Ans: Computer System: A computer is a system made up of two major components: I. Computer Hardware. II. Computer Software.
The following figure shows a computer system.
Fig : A Computer System I.Computer Hardware: The computer hardware is the physical equipment. The hardware component of computer system consists of 5 parts Input Devices. Central Processing Unit (CPU). Primary Storage. Output Devices. Auxiliary Storage Devices. The following figure shows the hardware components.
Introduction to components of a computer system : disks, primary and secondary memory, processor, operating system, compilers, creating, compiling and executing a program etc., Number systems. Introduction to Algorithms: steps to solve logical and numerical problems. Representation of Algorithm, Flowchart/Pseudo code with examples, Program design and structured programming. Introduction to C Programming Language: variables (with data types and space requirements), Syntax and Logical Errors in compilation, object and executable code ,Operators, expressions and precedence, Expression evaluation, Storage classes (auto, extern, static and register), type conversion, Bitwise operations: Bitwise AND, OR, XOR and NOT operators Conditional Branching and Loops: Writing and evaluation of conditionals and consequent branching with if, if-else, switch-case, ternary operator, goto, Iteration with for, while, do while loops I/O: Simple input and output with scanf and printf, formatted I/O, Introduction to stdin, stdout and stderr. Command line arguments
--------------------------------------------------------------------------------------------------------------------------------------------------- Input Devices: The input device is usually a keyboard where programs and data are entered into the computer. Other Input Devices : a touch screen , a mouse , a pen , an audio input unit.
Central Processing Unit ( CPU ): It is responsible for executing instructions such as arithmetic calculations , comparisons among data and movement of data inside the system. Today‗s computers may have one or more CPU‗s
Primary Storage: It is also known as main memory. It is a place where the programs and data is stored temporarily during processing. The Data in primary storage is erased when we turn off a personal computer or when we log off from a time-sharing computer (volatile).
Output Devices: The output device is usually a monitor or a printer to show output. If the output is shown on the monitor, it is a soft copy and if the output is printed on the printer, it is a hard copy.
Auxiliary Storage Devices (secondary storage devices): It is used for both input and output. It is also known as secondary storage. It is a place where the programs and data are stored permanently. When we turn off the computer the programs and data remain in the secondary storage, ready for the next time when we need them.
II. Computer Software: Software is the collection of Programs (instructions) that allow the hardware to do its job. There are two types of Computer Software. System Software Application Software The following figure shows the Computer Software.
Fig: Computer Software System Software: System Software consists of programs that manage the hardware resources of a computer and perform required information processing tasks. These programs a r e divided into three classes. Operating System Software. System Support Software. System Development Software.
i. Operating System Software: It provides services such as a user interface, files and data base access and interfaces to communication systems such as Internet protocols. The primary purpose of this software is to keep the system operating in an efficient manner while allowing the users access to the system.
---------------------------------------------------------------------------------------------------------------------------------------------------
2. Explain Creation and Running of programs? (or) Describe how the Developers will write the programs? (or) What are different steps followed in program development? Ans: Creating and running programs: It is the job of programmer to write and test the program. The following are four steps for creating and running programs: Writing and Editing the Program. Compiling the Program. Linking the Program with the required library modules. Executing the Program. A. Writing and Editing Program: The Software to write programs is known as text editor. A text editor helps us enter, change and store character data. Depending on the editor on our system, it could be used to write letters, create reports or write programs. Example : word processor. The text editor could be generalized word processor, but every compiler comes with associated text editor. Some of the features of editors are Search :To locate and replace statements. Copy , Paste :To copy and move statements. Format : To set tabs to align text. After the program is completed the program is saved in a file to disk. This file will be input to the compiler, it is known as source file. The following figure shows the various steps in building a C – program
Fig: Building a C - program
B. Compiling Programs: The code in a source file on the disk must be translated into machine language. This is the job of compiler which translates code in source file stored on disk into machine language. The C compiler is actually two separate programs: the preprocessor and the translator. The preprocessor reads the source code and prepares it for the compiler. It scans special instructions known as preprocessor commands. These commands tell the preprocessor to take for special code libraries, make substitutions in the code. The result of preprocessing is called translation unit. The translator reads the translation unit and writes resulting object module to a file that can be combined with other precompiled units to form the final program. An object module is the code in machine language. This module is not ready for execution because it does not have the required C and other functions included.
--------------------------------------------------------------------------------------------------------------------------------------------------- C. Linking Programs: C programs are made up of many functions. Example: printf( ) , cos( )… etc Their codes exists elsewhere , they must be attached to our program. The linker assembles all these functions, ours and the system‗s, into a final executable program.
D. Executing Programs : Once our program has been linked, it is ready for execution. To execute a program, we use operating system command, such as run to load the program in to main memory and execute it. Getting program into memory is the function of an Operating System programs called loader. Loader locates the executable program and reads it into memory. In a typical program execution, the program reads data for processing, either from user or from file. After the program processes the data, it prepares output. Data output can be to user‗s monitor or to a file. When program has executed, Operating System removes the program from memory.
3. Explain about Algorithm? (or) Define an Algorithm and State Properties of it? Ans: Algorithm : Algorithm is a finite set of instructions that , if followed accomplishes a particular task. Algorithm should satisfy the following criteria Input : Zero or more quantities are externally supplied. Output: At least one quantity is produced. Definiteness : Each instruction is clear and unambiguous. Ex: Add B or C to A Finiteness : Algorithm should terminate after finite number of steps when traced in all cases. Ex: Go on adding elements to an array Effectivenes: Every instruction must be basic i.e., it can be carried out, by a person using pencil and paper. Algorithm must also be general to deal with any situation. 4. List out the advantages and disadvantages of algorithm.
Ans:
Advantages of Algorithms: It provides the core solution to a given problem. the solution can be implemented on a computer system using any programming language of user‗s choice. It facilitates program development by acting as a design document or a blue print of a given problem solution. It ensures easy comprehension of a problem solution as compared to an equivalent computer program. It eases identification and removal of logical errors in a program. It facilitates algorithm analysis to find out the most efficient solution to a given problem. Disadvantages of Algorithms: In large algorithms the flow of program control becomes difficult to track. Algorithms lack visual representation of programming constructs like flowcharts; thus understanding the logic becomes relatively difficult.
--------------------------------------------------------------------------------------------------------------------------------------------------- Shows all elements and their relationships. Quick method of showing program flow. Checks program logic. Facilitates coding. Provides program revision. Provides program documentation. Advantages of a Flowchart : Flowchart is an important aid in the development of an algorithm itself. Easier to understand than a program itself. Independent of any particular programming language. Proper documentation. Proper debugging. Easy and clear presentation. Limitations of a Flowchart : Complex logic. Drawing is time consuming. Difficult to draw and remember. Technical detail.
7. Explain the Symbols in a Flowchart? Ans: Symbols : Symbols are divided in to the following two parts. I. Auxiliary Symbols. II. Primary Symbols. Some of the common symbols used in flowcharts are shown below:
---------------------------------------------------------------------------------------------------------------------------------------------------
8. Write an algorithm and flow chart for swapping two numbers Ans: To Swap two integer numbers: Algorithm : using third variable Step 1 : Start Step 2 : Input num1 , num Step 3 : temp = num Step 4 : num1 = num Step 5 : num2 = temp Step 6 : Output num1 , num Step 7 : Stop
Algorithm : without using third variable Step 1 : Start Step 2 : Input num1 , num Step 3 : calculate num1 = num1 + num Step 4 : calculate num2 = num1 – num Step 5 : calculate num1 = num1 – num Step 6 : Output num1 , num Step 7 : Stop
Flowcharts:
----------------------------------------------------------------------------------------------------------------------------------------------
10. Write an algorithm and flowchart to find the largest among three numbers. Ans: Algorithm: Step 1: Start Step 2: Input A, B, C Step 3: if A > B go to step 4 , otherwise go to step 5 Step 4: if A > C go to step 6 , otherwise go to step 8 Step 5: if B > C go to step 7, otherwise go to step 8 Step 6: print ― A is largest ‖ , go to step 9 Step 7: print ― B is largest ‖, go to step 9 Step 8: print ― C is largest ‖ , go to step 9 Step 9: Stop
Flowchart:
Algorithm: Step 1: Start Step 2: Input A, B, C Step 3: Let max = A Step 4: if B > max then max = B Step 5: if C > max then max = C Step 6: output max is largest Step 7: Stop
Flowchart:
----------------------------------------------------------------------------------------------------------------------------------------------
11. Write an algorithm and flowchart to find factorial of a number Hint: fact (4) = 1 * 2* 3* 4 Ans: Flowchart :
Algorithm: Step 1: Start Step 2: Input n Step 3: Initialize counter variable, i , to 1 and factors = 1 Step 4: if i <= n go to step 5 otherwise go to step 7 Step 5: calculate factors = factors * i Step 6: increment counter variable, i, and go to step 4 Step 7: output factors. Step 8: stop
----------------------------------------------------------------------------------------------------------------------------------------------
13. Write an algorithm and flowchart to find reverse of a number. Ans: Algorithm: Step 1: Start Step 2: Input n Step 3: Let rev= Step 4: if n<=0 go to step 8 Step 5: digit = n % 10 Step 6: rev = (rev * 10) + digit Step 7: n = n / 10 then go to step 4 Step 8: output rev Step 9: Stop
------------------------------------------------------------------------------------------------------------------------------------------
14. Write an algorithm and flowchart to find the Sum of individual digits if a given number Ans: Algorithm :- Step 1 : Start Step 2 : read n Step 3 : Sum = 0 Step 4 : While n > 0 do Step 4.1 : r = n % 10 Step 4.2 : Sum = Sum + r Step 4.3 : n = n/ Step 5 : End while Step 6 : Write Sum Step 7 : Stop
Flowchart :-
------------------------------------------------------------------------------------------------------------------------------------------ which specifies the operation to be performed on the given arguments.
During the execution, the assembly language program is converted into the machine code with the
help of an assembler. The simple assembly language statements had one-to-one correspondence with
the machine language statements. This one-to-one correspondence still generated complex programs.
Then, macroinstructions were devised so that multiple machine language statements could be
represented using a single assembly language instruction. Even today programmers prefer to use an
assembly language for performing certain tasks such as:
To initialize and test the system hardware prior to booting the operating system. This assembly language code is stored in ROM. To write patches for disassembling viruses, in anti-virus product development companies. To attain extreme optimization, for example, in an inner loop in a processor- intensive algorithm. For direct interaction with the hardware. In extremely high-security situations where complete control over the environment is required. To maximize the use of limited resources, in a system with serve resource constraints.
3. High-level languages: High level languages further simplified programming tasks by reducing the
number of computer operation details that had to be specified. High level languages like COBOL,
Pascal, FORTRAN, and C are more abstract, easier to use, and more portable across platforms, as
compared to low level programming languages. Instead of dealing with registers, memory addresses
and call stacks, a programmer can concentrate more on the logic to solve the problem with help of
variables, arrays or Boolean expressions.
High-level languages can be classified into the following three categories:
Procedure-oriented languages (third generation) Problem-oriented languages (fourth generation) Natural languages (fifth generation)
Procedure-oriented languages
High level languages designed to solve general-purpose problems are called procedural languages or
third generation languages. These include BASIC, COBOL, FORTRAN, C, C++, and JAVA, which
are designed to express the logic and procedure of a problem.
------------------------------------------------------------------------------------------------------------------------------------------ Problem-oriented languages
Problem-oriented languages are used to solve specific problems and are known as the fourth-
generation languages. These include query languages, report generators and application generators
which have simple, english-like syntax rules.
3. Natural languages
Natural languages are designed to make a computer to behave like an expert and solve problems. The
programmer just needs to specify the problem and the constraints for problem- solving. Natural
languages such as LISP and PROLOG are mainly used to develop artificial intelligence and expert
systems. These languages are widely known as fifth generation languages.
16. Explain the history of C? Ans: The history and development of C is shown as follows
Fig: History of ansi c
The root of all modern languages is ALGOL which is introduced in early 1960s.ALGOL was the first computer language to use a block structure. ALGOL gave the concept of structured programming to computer science community.
In 1967,Martin Richards developed a language called BCPL(Basic Combined Programming Language)primarily for writing system software. In 1970,Ken Thompson created a language using many features of BCPL and called it as ‗B‘.‘B‘ was used to create early versions of UNIX operating system at BELL laboratories.
------------------------------------------------------------------------------------------------------------------------------------------ Documentation section:
This section consists of a set of comment lines giving the name of the program, and other details. which the programmer would like to user later.
Ex:- /*Addition of two numbers */
// Addition of two numbers
Link section: Link section provides instructions to the compiler to link functions from the system library.
Ex:- # include
Definition section: Definition section defines all symbolic constants.
Ex:- # define A 10.
Global declaration section: Some of the variables that are used in more than one function throughout the program are called global variables and declared outside of all the functions. This section declares all the user-defined functions.
main() function section :
Every C program must have one main ( ) function section. This contains two parts. Declaration part: This part declares all the variables used in the executable part.
Ex:- int a,b; Executable part: This part contains at least one statement .These two parts must appear between the opening and closing braces. The program execution begins at the opening brace and ends at the closing brace. All the statements in the declaration and executable parts end with a semicolon (;).
Sub program section: This section contains all the user-defined functions that are called in the main() function. User-defined functions are generally placed immediately after the main() function, although they may appear in any order.
Ex:
------------------------------------------------------------------------------------------------------------------------------------------
18. What is a variable? Write the rules for constructing a variable?
Ans:
Variable: It is a data name that may be used to store a data value. It cannot be changed during the execution of a program. A variable may take different values at different times during execution. A variable name can be chosen by the programmer in a meaningful way so as to reflect its function or nature in the program.
Rules: Variable names may consist of letters, digits and under score( _ ) character. First char must be an alphabet or an ―_‖(underscore) Length of the variable cannot exceed upto 8 characters, some C compilers can Recognized upto 31 characters. White space is not allowed. Variables name should not be a keyword. Uppercase and lower case are significant. Ex:- mark,sum1,tot_value,delhi valid
Prics$, group one, char invalid
19. How to declare and initialize a variable? Ans: Declaration does two things:
It tells the compiler what the variable name is. It specifies what type of data the variable will hold.
The declaration of variables must be done before they are used in the program.
The syntax for declaring a variable is as follows:
data-type v1,v2,…….,vn;
v1,v2,…,vn are the names of variables.
Variables are separated by commas.
A declaration statement must end with a semicolon.
For example, valid declarations are: int count; int number, total; double ratio;
The simplest declaration of a variable is shown in the following code fragment: