Lecture 1 - Introduction
Lecture 1 - Introduction
(CS116)
Introduction
Programming: Instructing the Computer
• Computers are dumb devices that perform only the tasks applied by
the user
The C Programming Language
• The most influential programming language in the short history of computing!
• Compact, fast, and powerful
• Closer to the hardware than other high-level languages, introducing what is
known as “mid-level” language
• Very popular (top 5 – 10 world-wide)
• Backward compatible with the highly-popular C++
• Supports modular programming style (dividing your program into independent
units, each performing a specific task)
• Useful for a very wide spectrum of applications (operating systems development, embedded
systems, system software, game development, compilers and interpreters, database systems, network programming, real-
time systems, scientific and mathematical computing, graphics programming, security software, utilities and tools, artificial
intelligence, web development)
• C is the native language of UNIX and its popular variants (Linux, BSD)
The C Programming Language - History
• (1972) Developed by Dennis Ritchie
• (1983) Standardized by The American National Standards Institute (ANSI), producing the known as
ANSI C or C83
• (1990) Adopted by the International Standardization Organization (ISO), producing what is known as
ANSI/ISO C or C90
• (1999) Last major changes adopted
Levels of Programming Languages What software do we need to run C
programs on our machines?
Input
Output (return) Function
Return
printf Options (known as: escape sequences)
• printf(“Alsalamo Alikom \n");
• A function in the C library stdio.h that simply prints or displays its argument
(input) on screen
• \n means newline. After printing Assalamu Aleikom the typing cursor goes to
next line
A Program to Multiply Two Numbers
#include <stdio.h> Output:
The product of 7 and 3 is: 21
int main(void)
{
int x;
int y;
int z;
x = 7;
%d or %i int
y = 3;
%c char
z = x * y; %f float
printf(“The product of 7 and 3 is: %d\n“, z); %s string
return 0;
}
Declarations
• Declare an integer int x;
• Declare a character char x;
• Declare a float number (with decimal places) float x;
• Multiple declarations are allowed int x, y, z;
What is pi?
How can we represent pi?
How to compute a power
of 2?
Which values are integers
and which values are
floating-point numbers?
Area of a Circle (2)
#include<stdio.h>
int main()
{
float radius, area;
radius=3.1;
area = 3.14 * radius * radius;
printf("Area of Circle : %f", area);
return 0;
}
Let’s Test What We Learned
#include <stdio.h>
int main (void)
6 + a / 5 * b = 16
{ a / b * b = 24
int a = 25; c / d * d = 25.000000
int b = 2; -a = -25
float c = 25.0;
float d = 2.0;
printf ("6 + a / 5 * b = %i\n", 6 + a / 5 * b); /* */
printf ("a / b * b = %i\n", a / b * b);
printf ("c / d * d = %f\n", c / d * d);
printf ("-a = %i\n", -a);
return 0;
}