Académique Documents
Professionnel Documents
Culture Documents
Module Objectives:
Learn variable definition and value assignment Implement various programming constructs in C Implement modular solutions using C Understand the implementation and processing of Array in C Accept inputs from the terminal and Files Display output to the terminal and Files
AITI-KACE All Rights Reserved
Literature
Let Us C Yashwant Kanetkar Programming with C Schaums Outlines Practical C Programming Steve Oualline C by Example by Greg Perry Assessment
Theory Exam 30% Practical Exams 30% Assignment 20% Class Test 15% Attendance 5%
AITI-KACE All Rights Reserved
Part 1 Introduction to C
Section Objectives
Give brief Introduction to C Discuss C program structure How to execute a C program Learn about variables and constants in C Learn about Character Array and String Get to know what preprocessor directives are Learn about simple input and ouput in C
History of C
Evolved by Ritchie from two previous programming languages, BCPL and B Used to develop UNIX Used to write modern operating systems
Standardization
Many slight variations of C existed, and were incompatible Committee formed to create a "unambiguous, machine-independent" definition Standard created in 1989, updated in 1999
AITI-KACE All Rights Reserved
Why C?
Advantage: the programmer knows exactly how it works Disadvantage: time consuming
If a built-in function exists, generally make best use it rather than write your own Library functions carefully written, efficient, and portable
AITI-KACE All Rights Reserved
(With a Compiler)
(with an editor)
C program design
Define problem to be solved by the computer Define program's output Break problem into logical steps Write the program (using an editor)
Any editor can be used gedit, jedit, etc... Your C program must be saved with extension
{.c}
firstprogram.c
10
How it works!
Write / Edit Program Source Code
Executable
11
Go to the bin directory inside your home directory Create a folder call c_programs
To compile a c program: use the C compiler and provide a file which end with extension (.c)
AITI-KACE All Rights Reserved
12
C compiler on Linux
13
Anatomy of C Program
14
A first program in C */ #include <stdio.h> int main() { printf( "Welcome to C!\n" ); return 0;
int main() C program contain one or more functions, exactly one of which must be main
Parenthesis used to indicate a function ( ) int means that main "returns" an integer value Braces ({ and }) indicate a block printf () - display function A way to exit a function return 0, in this case, means that the program terminated normally
Welcome to C!
15
1. Initialize variables
2. Input
3. Sum 4. Print
Program Output
16
17