Beruflich Dokumente
Kultur Dokumente
R. Jothi
Computer Engineering
SOT PDPU
Overview
• Course Structure
• Why this course?
• Basics of Computer System
• Program/Software
• Introduction to C Language
• Turbo C Compiler
• C Program Example
• Text Books
Course Structure
• Regular Lab Exercises
• 2 Quiz
• Mid Semester Lab Exam
• End Semester Lab Exam
ROM A.L.U.
Auxiliary Memory
RAM
Cache
Memory Floppy Disks
Hard Disk
CD/Pen Drive
Text Books
• Programming in ANSI C,
Balagurusamy
• Let Us C, Yashavant
Kanetkar
• C: The Complete
Reference, Herbert Schildt
Program Vs. Software
• Program - A set of instructions telling a computer
what to do
– E.g. add two numbers
• Software – A set of programs to solve a particular
problem
– Programs + Associated manual/documentation
HISTORY OF C
• The C programming language was designed by
Dennis Ritchie at Bell Laboratories in the early 1970s
PROGRAM
CONSTANTS
VARIABLES
KEYWORDS
SPECIAL
ALPHABETS DIGITS SYMBOLS
C CHARACTER SET
• ALPHABETS : A … Z , a … z
• DIGITS : 0…9
• SPECIAL
SYMBOLS : ~ ` ! @
# % ^ & *
() _ - + =
| \ {} [] :
; “ ‘ < >
, . ? /
Structure of C Program
A Simple C Program to display “Hello
Electrical Engineers” Source
Code
/* This is my first program */
#include <stdio.h>
void main()
{
printf(“Hello Electrical Engineers”);
}
Hello.c
How does a computer execute a
program
Turbo C
• Integrated Development Environment and Compiler
for the C programming Language
• How to open it
– Run ->
– Type C:\TC\BIN\TC.EXE
First program in Turbo C
1. Open Turbo C
2. Type the program
3. Save the file as Hello.c
Use Key F2
4. Compile the program
Use ALT + C
5. Run the program
Use ALT + R
First program in Turbo C
1. Open Turbo C
2. Type the program
3. Save the file as Hello.c
Use Key F2
4. Compile the program
Use ALT + C and press Enter
5. Run the program
Use ALT + R press Enter
INPUT A, B
C=A+B
PRINT C
Few functions
scanf() : for reading input from user (keyboard)
scanf(“control string”, argument)
e.g. scanf(“%d”, &number1)
- read an integer value to the variable number1 and store it in the
memory location ( &number1);
getch() : output screen waits for some time until a key is hit
Program to Add Two Numbers
#include <stdio.h>
void main()
{
int a , b, c ; // declaration of variables
printf( " Enter first number ");
scanf(" %d ", &a);
printf( " Enter second number ");
scanf(" %d ", &b);
c = a+ b;
printf( " Sum of given two numbers is %d ", c );
}
Use getch() to see the o/p without using
#include <stdio.h>
ALT + F5
#include <conio.h>
void main()
{ int a , b, c;
clrscr();
printf( " Enter first number \n");
scanf(" %d ", &a);
printf( " \nEnter second number ");
scanf(" %d ", &b);
c = a+ b;
printf( " \nSum of given two numbers is %d ", c );
getch();
}
Remember
1. C Language is case sensitive
a and A are different
2. Every statement in C program must be terminated
by a semicolon.
3. Every C program must have one main function.
4. Check for parenthesis balance
{ }
5. Save the program then and there using ALT+ F
Save
6. Every variable must be declared.
7. clrscr() must be used after variable declaration.
8. Include <conio.h> while using getch() and clrscr();
Remember
Always start your program this way
#include <stdio.h>
void main()
{
// variable declaration
clrscr(); // to clear previous o/p from screen
// actual computation
getch()
}
Input - scanf()
scanf(“control string”, argument)