C Intro 1
C Intro 1
C Intro 1
• To computers
HARDWARE
• Hardware refers to the physical elements of a computer. This is also sometime called
the machinery or the equipment of the computer. Examples of hardware in a computer
are the keyboard, the monitor, the mouse and the central processing unit. However,
most of a computer's hardware cannot be seen; in other words, it is not an external
element of the computer, but rather an internal one, surrounded by the computer's casing
(tower). A computer's hardware is comprised of many different parts, but perhaps the
most important of these is the motherboard. The motherboard is made up of even more
parts that power and control the computer.
• In contrast to software, hardware is a physical entity. Hardware and software are
interconnected, without software, the hardware of a computer would have no function.
However, without the creation of hardware to perform tasks directed by software via the
central processing unit, software would be useless.
• Hardware is limited to specifically designed tasks that are, taken independently, very
simple.
Computer -- Hardware
Input Output
Key board Storage Program Storage Area
Storage Monitor
Area Area
Mouse Working Storage Area Printer
Input Devices Output Devices
Register 1
Register 2
……
Arithmetic
……
Register N and
Logic Unit
Secondary
MicroStorage Devices
Processor
Software ?
Example:
Operating Systems, Compiler, Loader, Linker, Interpreter.
Application Software:
Example:
1 #include<stdio.h>
2 int main(void)
The only language the computer can understand is machine
3 { language (binary language).
4 int n1, n2,product;
5 printf(“Enter two numbers : “); A high level language is an English like language where one
6 scanf(“%d %d”,&n1,&n2); instruction typically translates into a series of machine-
7 product = n1 * n2;
language instructions.
8 printf(“%d”,product);
9 return 0;
1 } A low level language corresponds closely to machine code
0 so that a single low-level language instruction translates to a
single machine language instruction.
Program Development Cycle:
1. Analyze: Define the problem
2. Design: Plan the solution to the problem
3. Code: Translate the algorithm into a
programming language.
4. Debug and Test: Locate and remove any
errors in the program.
5. Complete the Documentation: Organize all
the materials that describe the program.
Chapter 2- Visual Basic Schneider 25
Program Development Steps
Statement of Problem 3.a)Compilation
a) Working with existing system and using proper Translate the program into machine code. This
questionnaire, the problem should be explained process is called as Compilation. Syntactic errors are
clearly. found quickly at the time of compiling the program.
b) What inputs are available, outputs are required These errors occur due to the usage of wrong syntaxes
and what is needed for creating workable solution for the statements.
should be understood clearly. Eg: x=a*y+b
1)Analysis There is a syntax error in this statement, since, each
a) The method of solutions to solve the problem can and every statement in C language ends with a
be identified. semicolon (;).
b) We also judge that which method gives best
results among different methods of solution. 3.b)Execution
2)Designing The next step is Program execution. In this phase, we
a) Algorithms and flow charts will be prepared. may encounter two types of errors.
b) Keep focus on data, architecture, user interfaces Runtime Errors: these errors occur during the
and program components. execution of the program and terminates the program
abnormally.
3)Implementation
Logical Errors: these errors occur due to incorrect
The algorithms and flow charts developed in the
usage of the instructions in the program. These errors
previous steps are converted into actual programs in
are neither detected during compilation or execution
the high level languages like C.
nor cause any stoppage to the program execution but
produces incorrect ouz
Programming Tools:
• Algorithm
• Flowchart
• Pseudocode
#include<stdio.h> start
#include<conio.h> Flow chart:
main() read num
{
int num;
printf(“Enter any number”); If No
Yes
scanf(“%d”,&num); num%2=0
if(num%2==0)
printf(“%d is even”,num);
else print num print num
printf(%d is odd”,num); is odd
is even
}
(Program in C language) stop
Structure of C program
/*Program to find
Documentation Section
area and perimeter of Circle */
#include<stdio.h> Linkage Section
#define PI 3.1415 Definition Section
float radius;
float area(); Global Declaration Section
float perimeter();
int main()
{
float a, p; Main Function Section
printf(“Enter radius : “);
scanf(“%f”,&radius); Local Declaration Part
a = area(); Executable Code Part
p = perimeter();
printf(“Area of Circle : %f”,a);
printf(“Perimeter : %f”,p);
}
float area()
Sub Program Section
{
return (PI * radius * radius);
Function1()
}
Function2()
float perimeter()
……………
{
FunctionN()
return (2 * PI * radius);
}
Executing a C program
#include<stdio.h>
Text int main()
{ Translators are system software
Editor ……. prog1.c used to convert high-level
language program into
C-compiler compiles
machine-language code.
Compiler : Coverts the entire
010110 100 Syntax Yes source program at a time
……………. Errors?
01011 101 into object code file, and
No saves it in secondary storage
Object machine code permanently. The same
adds prog1.obj object machine code file will
Linker
be executed several times,
00101010
Executable whenever needed.
………….
01010101 machine code Interpreter : Each statement of
prog1.exe source program is translated
machine code of
library file into machine code and
Executes executed immediately.
C-Runtime
Translation and execution of
Feeds
Runtime
each and every statement is
Input Yes repeated till the end of the
or Logic
Errors ? program. No object code is
saved. Translation is
repeated for every execution
Output of the source program.