Pop

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

MODULE I

1. Define computer. Describe the various types of computer based on speed, memory and
cost(8)
2. Discuss the variants of microcomputer that are widely used today(6)
3. Write a short note on the characteristics of a computer (6)
4. List any three input and three output devices of a computer and explain any one each(5)
5. Develop an algorithm to find the area and perimeter of a circle. Also define an
algorithm(6)
6. Write a c program to find area and perimeter of a rectangle (5)
7. Draw a flowchart and C program which takes as input p,t,r. Compute the simple interest
and display the result(6)
8. Define Pseudocode. Write a pseudocode to find sum and average of 3 numbers (5)
9. What is variable? What are the rules to construct variable? Classify the following as
valid/invalid Identifiers(8)
num2 ii) $num1 iii) +add iv) a_2 v) 199_space vi) _apple vii)#12
10. Explain the structure of C program in detail. Write a sample program to demonstrate the
components in the structure of C program(8)
11. Demonstrate formatted output of integer in C with suitable example(6)
12. List the basic data types available in C. Explain with example(8)
13. Define a Token. Explain the different types of tokens available in c
MODULE I
1. Define computer. Describe the various types of computer based on speed,
memory and cost(8)
Computer Definition
A computer is defined as an electronic device that is designed to accept data,
perform the required mathematical and logical operations at high speed, and output the
result

Computers can be broadly classified into four categories based on Speed, Memory &
Cost
o Microcomputers
o Minicomputers
o Mainframe computers
o Supercomputers
Classifications of
Computer

Mainframe
Microcomputer Minicomputer Supercomputer
Computer

 Microcomputers
o Microcomputers, commonly known as PCs, are very small and cheap. The first
microcomputer was designed by IBM in 1981 and was named IBM-PC,
o Another type of popular PC is designed by Apple. PCs designed by IBM and other
PC-compatible computers have a different architecture from that of Apple
computers.
o Moreover, PCs and PC-compatible computers commonly use the Windows
operating system, while Apple computers use the Macintosh operating system
(MacOS).
o PCs can be classified into the following categories
 Desktop PC
 Laptop
 Workstation
 Network Computers
 Handheld Computers
 Smart Phone
 Tablet PC
 Minicomputers
o Minicomputers are smaller, cheaper, and slower than mainframes.
o Also known as midrange computers, the capabilities of minicomputers fall between
mainframe and personal computers
o Widely used in business, education, hospitals, government organizations etc.
o Minicomputers can also be used as servers in a networked environment, and
hundreds of PCs can be connected to it
o The first minicomputer was introduced by Digital Equipment Corporation (DEC)
in the mid-1960s, Other manufacturers of minicomputers include IBM Corporation
(AS/400 computers), Data General Corporation, and Prime Computer
 Mainframe Computers
o Mainframe computers are large-scale computers (but smaller than supercomputers)
o These are very expensive and need a very large clean room with air conditioning,
thereby making them very costly to deploy
o As with supercomputers, mainframes can also support multiple processors
o For example, the IBM S/390 mainframe can support 50,000 users at the same time.
Users can access mainframes by cither using terminals or via PCs
o Dumb Terminals
 Dumb terminals consist of only a monitor and a keyboard (or mouse)
 They do not have their own CPU and memory and use the mainframe
system's CPU and storage devices
o Intelligent Terminals
 intelligent terminals have their own processor and thus can perform some
processing operations. However, just like the dumb terminals, they do not
have their own storage space.
 Usually, PCs are used as intelligent terminals to facilitate data access and
other services from the mainframe system
o Supercomputers
o Supercomputer is the fastest, most powerful, and most expensive computer
o Supercomputers were first developed in the 1980s to process large amounts of data
and to solve complex scientific problems
o Supercomputers use parallel processing technology and can perform more than one
trillion calculations in a second
o A single supercomputer can support thousands of users at the same time, Such
computers are mainly used for weather forecasting, nuclear energy research,
aircraft design, automotive design, online banking, controlling industrial units, etc.
o Some examples of supercomputers are CRAY=Ty CRAY-2, Control Data CYBER
205, and ETA A-10

2. Discuss the variants of microcomputer that are widely used today (6)
Microcomputers
o Microcomputers, commonly known as PCs, are very small and cheap. The first microcomputer
was designed by IBM in 1981 and was named IBM-PC,
o Another type of popular PC is designed by Apple. PCs designed by IBM and other PC-
compatible computers have a different architecture from that of Apple computers.
o Moreover, PCs and PC-compatible computers commonly use the Windows operating system,
while Apple computers use the Macintosh operating system (MacOS).
o PCs can be classified into the following categories
 Desktop PCs
o Most popular model of PCs
o System unit can be placed flat on a desk or table
o Widely used in homes and offices
 Laptops
o Small microcomputers that can easily fit inside a briefcase.
o Handy to carry from one place to another
o Operated by battery and do not always have to be plugged in like desktop computers
o The memory and storage capacity is equivalent to desktop computers
o laptops also have hard disk drives, USB drives,
o For input, laptops have a built-in keyboard and a trackball/touchpad, which is used
as a pointing device
 Workstations
o Workstations are single-user computers that have the same features as PCs, but
their processing speed matches that of a minicomputer or mainframe computer.
o Workstation computers have advanced processors, more RAM and storage capacity
than PCs
o more expensive and powerful than a normal desktop computer
o widely used as powerful single-user computers by scientists, engineers, architects,
and graphic designers
o They can also be used as servers in a networked environment
 Network Computers
o Network computers have less processing power, memory, and storage than a
desktop computer
o These are specially designed to be used as terminals in a networked environment
o For example, some network computers are specifically designed to access data
stored on a network
o Some network computers do not have any storage space and merely rely on the
network’s server for data storage and processing tasks
o Network computers that are specifically designed to access only the Internet or
intranet are often known as Internet PCs or Internet boxes
o Cheaper less maintenance than PCs
 Handheld Computers
o small personal computing devices that are commonly known as handheld
computers, or mobile computers
o These computers are called handheld computers because they can fit in one hand
o Handheld computers are very small in size, and hence they have small-sized screens
and keyboards
o These computers are preferred by business travelers and mobile employees whose
jobs require them to move from place to place.
o Example
 Smartphones
 in addition to basic phone capabilities, they also facilitate the users
to access the Intemet and send e-mails, edit Word documents,
generate an Excel sheet, create a presentation, and lots more
 The four major mobile operating systems are iOS, Android,
BlackBerryOS, and Windows
 Tablet PC’s
 A tablet PC is a computing device that is smaller than a laptop, but
bigger than a smartphone
 Features such as user-friendly interface, portability, and touch
screen have made them very popular in the last few years

3. Write a short note on the characteristics of a computer (6)

Characteristics of Computer
Economical

 Speed
o Computers can perform millions of operations per second
o Processing speed is very high
o The speed of computers is usually given in nanoseconds and picoseconds,
 Accuracy
o A computer is a very fast, reliable, and robust electronic device
o It always gives accurate results, provided the correct data and set of instructions are
input to it
o The output generated by a computer depends on the given instructions and input
data
 Diligence
o Unlike humans, computers never get tired of a repetitive task
o It can continually work for hours without creating errors
o if a large number of executions need to be executed, each and every execution
requires the same duration, and is executed with the same accuracy.
 Versatility
o Versatility is the quality of being flexible.
o computers are versatile devices as they can perform multiple tasks of different
nature at the same time.
 Reliability
o The output of the computer depends upon the input given
o So it gives consistent output with similar set of inputs, it won’t differ
 Automation
o Computers are automatable devices that can perform a task without any user
intervention
o The user just needs to assign the task to the computer, after which it automatically
controls different devices attached to it and executes the program instructions
 Memory
o Similar to humans, computers also have memory
o computers also have internal or primary memory (storage space) as well as external
or secondary memory.
o Internal memory of computers is very expensive and limited in size, the secondary
storage is cheaper and of bigger capacity.
o The computer stores a large amount of data and programs in the secondary storage
space. The stored data and programs can be retrieved and used whenever required
 Economical
o Today, computers are considered as short-term investments for achieving long-term
gains
o Computers also reduce manpower requirements and leads to an elegant and
efficient way of performing various tasks.
o Computers save time, energy, and money

4. List any three input and three output devices of a computer and explain any one
each(5)
Input Devices
 Keyboard
 Mouse
 Track ball
 Track Pen
Keyboard
 Main input device for computer
 All kind of typing works, playing games, accessing menus can be done
 Most keyboards have 80 to 110 keys
 Typing keys
 Numeric keys
 Function keys
 Advantages
 Easy to use and cheap
 Disadvantages
 Keyboard cannot be used to draw figures
 The process of moving the cursor to some other position is very slow
Output Devices
 Monitor
 Printer
 Plotter
 Speaker
Printers
 Printer is a device that outputs text and graphics information obtained from the
computer and prints it on to a paper
 Printers are available in the market in a variety of size, speed, sophistication, and
cost
 The qualities of printer include
 Color: Colored printouts are needed for presentations or maps and other pages
where color is part of the information. They are more expensive
 Memory: Most printers have a small amount of memory that can be expanded by
the user. Having more memory makes enhances the speed of printing
 Resolution: The resolution of a printer means the sharpness of text and images on
paper. It is usually expressed in dots per inch (dpi). Even the least inexpensive
printer provides sufficient resolution for most purposes at 600 dpi.
 Speed: Speed means number of pages that are printed in one minute. While high
speed printers are a little expensive, the inexpensive printers on the other hand can
print only about 3 to 6 sheets per minute. Color printing is even slower
 Different Types of Printer
o Impact Printer
 These printers print characters by striking an inked ribbon against
the paper.
 Types of Impact Printers
 Dot Matrix Printers
 Daisy Wheel Printers
 Line Printers
 Band Printer
o Non-Impact Printer
 Non-impact printers are much quieter than impact printers, as their
printing heads do not strike the paper
 They offer better print quality, faster printing, and the ability to
create prints that contain sophisticated graphics
 Types of Non-Impact Printers
 Inkjet Printers
 Laser Printers

5. Develop an algorithm to find the area and perimeter of a circle. Also


define an algorithm (6)
Algorithm Definition
An algorithm is a sequence of instructions performed in a predetermined sequence in
order to solve a problem or complete a work. It provides a blueprint to writing a
program to solve a particular problem. It is considered to be an effective procedure for
solving a problem in a finite number of steps
Working of Algorithm
o Input
o Processing
o Output
o Termination
Algorithm to find the area and perimeter of a circle:

Input: radius of a circle


Step 1: Start

Step 2: Read the radius

Step 3: Calculate area and Perimeter

area = 3.14*radius*radius

perimeter = 2*3.14*radius

Step 4: Print the area and perimeter

Step 5: Stop
6. Write a c program to find area and perimeter of a rectangle (5)
C Program to find area & perimeter of rectangle
#include <stdio.h>
int main()
{

int l,b,area, Perimeter;


printf("Enter l and b values:");
scanf("%d%d",&l,&b);
area = l*b;
perimeter = 2*(l+b);
printf("Area of Rectangle = %d\n", area);
printf("Perimeter of Rectangle = %d\n", perimeter);
return 0;
}
Output
Enter l and b values:10 20
Area of Rectangle = 200
Perimeter of Rectangle = 60

7. Draw a flowchart and C program which takes as input p,t,r. Compute the simple
interest and display the result(6)
Simple Interest Formula
Simple Interest = (P * T * R)/100
P – principle
T – Time
R – Interest rate
C Program to calculate Simple Interest

#include <stdio.h> Start


int main()
{

int p,t,r,si; Input p,t,r


printf("Enter p,t,r values:");
scanf("%d%d%d",&p,&t,&r);
si = (p * t * r) / 100;
printf("Simple Interest = %d\n", si); si = (p * t * r) / 100
return 0;
}
Output
Enter p,t,r values:25000
10 Output si
12
Simple Interest = 30000

Flowchart Stop
8. Define Pseudocode. Write a pseudocode to find sum and average of 3
numbers (5)
Pseudocodes
 Pseudocode is a compact and informal high-level description of an algorithm that uses
the structural conventions of a programming language
 Pseudocodes are an outline of a program that can easily be converted into programming
statements
 An ideal pseudocode must be complete, describing the entire logic of the algorithm, so
that it can be translated straightaway into a programming language.
 Details include variable declarations, system-specific code, and subroutines
 Consist of short English phrases that explain specific tasks
 They should not include keywords in any specific computer language
 The sole purpose of pseudocodes is to enhance human understandability of the solution

 Pseudocode to find sum and average of 3 numbers


Start
Accept two values a,b and c
Sum =a+b+c;
Average = (a+b+c)/3
Printf sum and average
End

9. What is variable? What are the rules to construct variable? Classify the
following as valid/invalid Identifiers(8)
i) num2 ii) $num1 iii) +add iv) a_2 v) 199_space vi) _apple vii)#12
Variables
 A variable is defined as a meaningful name given to a data storage location in computer
memory
 When using a variable, we actually refer to address of the memory where the data is
stored.
 C language supports two basic kinds of variables—numeric and character
o Numeric Variables
 Numeric variables can be used to store either integer values or floating
point values.
o Character Variables
 Character variables are just single character enclosed within double
quotes
 Characters will be from any ASCII character set as letters(‘a’, ‘A’),
numbers(‘5’) or special characters(‘&’)
 Rules for Forming Variable Names
1. First character must be an alphabet or underscore
2. Must consist of only letters, digits or underscore
3. Only first 31 characters are significant
4. Keywords should not be used
5. No two successive underscores in naming variables
6. Variables are case sensitive
7. Should not include white space, special characters or punctuation marks
 Classify the following as valid/invalid Identifiers

i) num2 - Valid
ii) $num1 - Invalid because of using special character $
iii) +add - Invalid because of using + symbol
iv) a_2 - Valid
v) 199_space - Invalid, because variables should start with character or
underscore
vi) _apple - valid
vii) #12 - Invalid because of using special character #

10.Explain the structure of C program in detail. Write a sample program to


demonstrate the components in the structure of C program (8)

Structure Of C Program
 C program is composed of preprocessor commands, a global declaration section, and one
or more functions
 The preprocessor directives contains special instructions that indicate how to prepare the
program for compilation
 One of the most important and commonly used preprocessor commands is include which
tells the compiler that to execute the program, some information is needed from the
specified header file.
 A C program contains one or more functions, where a function is defined as a group of C
statements that are executed together
 The statements in a C function are written in a logical sequence to perform a specific task
 The main() function is the most important function and is a part of every C program. The
execution of a C program begins at this function.
 All functions (including main()) are divided into two parts—the declaration section and the
statement section
 The declaration section precedes the statement section and is used to describe the data that
will be used in the function
 The data declared within a function are known as local declaration as that data will be
visible only within that function i.e life-time of the data will be only till the function ends,
 The statement section in a function contains the code that manipulates the data to perform
a specified task

Writing first C Code


//program to print a messagex
#include<stdio.h> //Header File section
int main() //main function
{ //start of main
int a, b,c; //local declaration
printf(“Enter a and b values:”);
scanf(“%d%d”,&a,&b); //Executable statements
c= a+b;
printf(“Sum = %d”,c);
return 0;
} //end of main
Output
Enter a and b values: 10 30
Sum = 40
11.Demonstrate formatted output of integer in C with suitable example(6)

Formatted Output Statement in c - printf()


 The printf function (stands for print formatting) is used to display information required by
the user and also prints the values of the variables.
 For this, the printf function takes data values, converts them to a text stream using
formatting specifications in the control string and passes the resulting text stream to the
standard output.
 Syntax

printf(“ any message “); - to display any message in the output screen

printf ("control string", variable list);


o control string - The control string may also contain the text to be printed like
instructions to the user, captions, identifiers, or any other text to make the output
readable. The control characters can also be included in the printf statement. These
control characters include \n, \t, \r, \a, etc
o variable list specifies the list of variables
 Example
o printf(“ Welcome to c programming”);
o printf(“%d”,a);
o printf(“sum = %d”,sum);
o printf(“a=%d b=%d c=%d”,a,b,c);
12.List the basic data types available in C. Explain with example(8)
Basic Data Types In C
 Data type specifies the size and type of information variable stores
 C language provides very few basic data types.
 Table lists the primary data types. their size, range, and usage for a C programmer on
a 16-bit computer.

Character Data Type


 Character occupies 1 byte to store single character.
 C does not provide any data type for storing text, This is because text is made up
of individual characters.
 The range of char is given as —128 to 127.
 In memory characters are stored in their ASCII codes.
 For example, character ‘A’ will be stored in memory as the ASCII code 65
Integer Data Type
 Integers are whole numbers without fraction part
 Integers occupy 2 bytes of storage
 Size of integer ranges between -32768 to +32767
 The 3 variants of integer data type are short int, int & long int in both signed and
unsigned form
 The range of unsigned integer for a 16-bit machine is 0 to 65635

Floating Point Data Type


 Floating point or real numbers are stored in 32 bits with 6 digits of precision
 Declared with float keyword
 Float is used to declare single precision value
 Stored in mantissa and exponent form
 Range of float is 3.4E-38 to 3.4E+38
Double
 Double data type uses 64 bits with 14 digits of precision
 Double represents the same data type as float but with greater precision
 Stored in mantissa and exponent form
 double is used to declare double precision value
 To extend the precision further, use long double which uses 80 bits
 Range of float is 1.7E-308 to 1.7E+308

Void
 Void data type has no value
 Usually used to specify the type of function
 Function with void mean it does not return any value to the calling function
 Also plays a role of generic data type

13.Define a Token. Explain the different types of tokens available in c (6)

 Tokens are the basic building blocks in C language.


 Token is the smallest individual unit in a C program
 There are six main types of tokens in C
Keywords
 C has a set of reserved words often known as keywords that cannot be used as an
identifier.
 All keywords are basically a sequence of characters that have a fixed meaning.

List of keywords in C

Identifiers
 Identifiers identifies data and other objects in the program.
 Identifiers are basically the names given to program elements such as variables, arrays, and
functions.
 Identifiers may consist of sequence of letters, numerals, or underscores
 Rules for Forming Identifier Names
o First character must be an alphabet or underscore
o Must consist of only letters, digits or underscore
o Only first 31 characters are significant
o Keywords should not be used
o No two successive underscores
o Should not include white space, special characters or punctuation marks
 Examples of valid identifiers include:
roll_number, marks, name, emp_number, basic_pay, HRA, DA, dept_code,
DeptCode, RollNo, EMP_NO
 Examples of invalid identifiers include:
23_student, Xmarks, @name, #emp_number, basic.pay, -HRA, (DA),
&dept_code, auto
 C is a case-sensitive language. Therefore rno, Rno, RNo, RNO are considered as different
identifiers

Constants
 Constants are identifiers whose values do not change during program execution
 Values of constants can never be changed.
 Constants are used to define fixed values like PI
 A constant is an explicit data value specified by the programmer,
 The value of the constant is known to the compiler at the compile time.

String
 A string is a sequence of characters enclosed in double quotes.
 Example: “hello”
 By default last character of any string is null character(\0)
Special Symbols
 Symbols other than alphabets, digits and white space characters like
!,@,#,$,%,^,&,*,(,),{,},[,] etc..
Operators
 Operator is a symbol which operates on value or variable ex: a+b, here + is a operator
 Different types of Operators includes
o Arithmetic Operator
o Relational Operator
o Logical Operator
o Assignment Operator
o Conditional Operator
o Bitwise Operator
o Sizeof Operator
o Shift Operator

You might also like