Pps Using C r20 - Unit-1
Pps Using C r20 - Unit-1
UNIT I
Computer Systems:-
A computer is a system made of two major components: hardware and software. The
computer hardware is the physical equipment. The software is the collection of programs
(instructions) that allow the hardware to do its job.
The input device is usually a keyboard where programs and data are entered into the
computers. Examples of other input devices include amouse, a pen or stylus, a touch screen,
or an audio input unit.
The central processing unit (CPU) is responsible for executing instructions
such as arithmetic calculations, comparisons amongdata, and movement
of data inside the system.
The output device is usually a monitor or a printer to show output. If theoutput is
shown on the monitor, we say we have a soft copy. If it is printed on the printer, we
say we have a hard copy.
Auxiliary storage, also known as secondary storage, is used for both input and
output. It is the place where the programs and data are storedpermanently. When
we turn off the computer, or programs and data remain in the secondary storage,
ready for the next time we need them.
Computer Software :-
Computer software is divided in to two broad categories: systemsoftware
and application software.
System software manages the computer resources .It provides theinterface
between the hardware and the users.
Application software, on the other hand is directly responsible forhelping
users solve their problems.
Computing Environments:-
Computing Environment is a collection of computers / machines, software, and
networks that support the processing and exchange of electronic information meant to
1|Page
support various types of computing solutions. With the advent if technology the
computing environments havebeen improved.
Computer Languages:-
To write a program for a computer, we must use a computer language. Over the
years computer languages have evolved from machinelanguages to natural languages.
Machine Languages:-
In the earliest days of computers, the only programming languagesavailable were
machine languages. Each computer has its own machine language, which is made of
streams of 0’s and 1’s.
Instructions in machine language must be in streams of 0’s and 1’s because theinternal
circuits of a computer are made of switches transistors and other electronic devices that
can be in one of two states: off or on. The off state is represented by 0 , the on state is
represented by 1.
The only language understood by computer hardware is machine language.
Symbolic Languages:-
In early 1950’s Admiral Grace Hopper, A mathematician and naval officer
developed the concept of a special computer program that wouldconvert programs
into machine language
2|Page
Computer does not understand symbolic language it must be translated to the machine
language. A special program called assemblertranslates symbolic code into machine language.
High Level Languages:-
Symbolic languages greatly improved programming effificiency; theystill required
programmers to concentrate on the hardware that they were using.
Working with symbolic languages was also very tedious because each machine
instruction has to be individually coded. The desire to improve programmer
efficiency and to change the focus from the computer to the problem being solved
led to the development of high-level language.
3|Page
Click on File -> New in C Editorwindow
Type the program
Save it as FileName.c (Use shortcut key F2 to save)
We use a shortcut key Ctrl + F9 to run a C program. Whenever we press Ctrl + F9, the .exe
file is submitted to the CPU. On receiving .exe file, CPU performs the task according to the
instruction written in the file. The result generated from the execution is placed in a window
called User Screen.
The file which contains c program instructions in high level language is said to be source code.
Every c program source file issaved with .c extension, for example Sample.c.
4|Page
Whenever we press Alt + F9 the source file is submitted to the compiler. Compiler checks
for the errors, if there are any errors, itreturns list of errors, otherwise generates object code
in a file withname Sample.obj and submit it to the linker.
Linker combines the code from specified header file into object file and generates
executable file as Sample.exe. With this compilation process completes.
Now, we need to Run the executable file (Sample.exe). To run a program we press Ctrl
+ F9. When we press Ctrl + F9 the executable file is submitted to the CPU.
Then CPU performs the task according to the instructions writtenin that program and place
the result into UserScreen.
Then we press Alt + F5 to open UserScreen and check the result ofthe program.
Overall Process:-
5|Page
Decimal equivalent of any octal number is sum of product of each digit with itspositional
value.
Storing Integers:-
Integers are commonly stored using a word of memory, which is 4 bytesor 32 bits, so
integers from 0 up to 4,294,967,295 (232 - 1) can be stored.
Below are the integers 1 to 5 stored as four-byte values (each rowrepresents
one integer).
This may look a little strange; within each byte (each block of eight bits), the bits are
written from right to left like we are used to in normal decimal notation,but the bytes
themselves are written left to right! It turns out that the computer does not mind which
order the bytes are used (as long as we tell the computer what the order is) and most
software uses this left to right order for bytes.7.3
Two problems should immediately be apparent: this does not allow for negative
values, and very large integers, 232 or greater, cannot be stored in aword of memory.
Real numbers:-
Real numbers (and rationals) are much harder to store digitally thanintegers.
Recall that k bits can represent 2k different states. For integers, the first state can
represent 0, the second state can represent 1, the third state can represent 2, and so
on. We can only go as high as the integer 2k - 1, but atleast we know that we can
account for all of the integers up to that point.
Unfortunately, we cannot do the same thing for reals. We could say that thefirst state
6|Page
represents 0, but what does the second state represent? 0.1? 0.01? 0.00000001?
Suppose we chose 0.01, so the first state represents 0, the second state represents 0.01,
the third state represents 0.02, and so on. We can now only go as high as 0.01 x (2k - 1),
and we have missed all of the numbers between 0.01 and 0.02 (and all of the numbers
between 0.02 and 0.03, and infinitely many others).
7|Page
}
6. Sub program or function section
8|Page
1. DOCUMENTATION SECTION : comes first and is used to document the use of logic or
reasons in your program. It can be used to write the program's objective, developer and
logic details. The documentation is done in C language with /* and */ . Whatever is written
between these two are called comments.
2. LINKING SECTION : This section tells the compiler to link the certain occurrences of
keywords or functions in your program to the header files specified in this section.
e.g. #include <stdio.h>
3. DEFINITION SECTION : It is used to declare some constants and assign them some value.
e.g. #define MAX 25
Here #define is a compiler directive which tells the compiler whenever MAX is found in the
program replace it with 25.
4. GLOBAL DECLARATION SECTION : Here the variables which are used through out the
program(including main and other functions) are declared so as to make them global(i.e
accessible to all parts of program)
e.g. int i; (before main())
5. MAIN FUNCTION SECTION : It tells the compiler where to start the execution
frommain()
{
point from execution starts
}
main function has two sections
1. declaration section : In this the variables and their data types are declared.
2. Executable section : This has the part of program which actually performs the task we need.
6. SUB PROGRAM OR FUNCTION SECTION : This has all the sub programs or
thefunctions which our program needs.
/* simple program in c */
#include<stdio.h>
main()
{
printf(“welcome to c programming”);
} /* End of main */
IDENTIFIERS :-
Names of the variables and other program elements such as functions,array, etc,
are known as identifiers.
There are few rules that govern the way variable are named (identifiers).
9|Page
1. Identifiers can be named from the combination of A-Z, a-z, 0-9,
_(Underscore).
2. The first alphabet of the identifier should be either an alphabet or an
underscore. digit are not allowed.
3. It should not be a keyword.Eg:
name, ptr, sum
After naming a variable we need to declare it to compiler of what data type itis .
The format of declaring a variable isData-
where data type could be float, int, char or any of the data types.
id1, id2, id3 are the names of variable we use. In case of single variable nocommas are
required.
Eg float a, b, c;
int e, f, grand total;
char present_or_absent;
DATA TYPES :-
To represent different types of data in C program we need different data types. A data
type is essential to identify the storage representation and thetype of operations that can
be performed on that data. C supports four different classes of data types namely
1. Basic Data types
2. Derives data types
3. User defined data types
4. Pointer data types
BASIC DATA TYPES:
All arithmetic operations such as Addition , subtraction etc are possible onbasic data types.
E.g.: int a,b;
Char c;
VARIABLES :-
A quantity that can vary during the execution of a program is known as a variable. To
identify a quantity we name the variable for example if we arecalculating a sum of two
numbers we will name the variable that will hold the value of sum of two numbers as
'sum'.
CONSTANTS : -
A quantity that does not vary during the execution of a program is known as a
constant supports two types of constants namely Numeric constants and
character constants.
NUMERIC CONSTANTS:
1. Example for an integer constant is 786,-127
2. Long constant is written with a terminal ‘l’or ‘L’,for example 1234567899Lis a Long
constant.
CHARACTER CONSTANTS:-
A character constant is written as one character with in single quotessuch as ‘a’. The
value of a character constant is the numerical value of the character in the machines
character set.
INPUT AND OUTPUT STATEMENTS :-
The simplest of input operator is getchar to read a single character fromthe input
device.
varname=getchar();
you need to declare varname.
The simplest of output operator is putchar to output a single character onthe output
device.
putchar(varname)
The getchar() is used only for one input and is not formatted. Formatted input refers
to an input data that has been arranged in a particular format, forthat we have scanf.
#include<stdio.h>
main()
11 | P a g e
{
int a,b;
float c;
printf("Enter any number");
a=getchar();
printf("the char is ");
putchar(a);
printf("Exhibiting the use of scanf");
printf("Enter three numbers");
scanf("%d%d%f",&a,&b,&c);
printf("%d%d%f",a,b,c);
}
12 | P a g e