CS 101 Lecture 1 PDF
CS 101 Lecture 1 PDF
1
CS 101
Computer Programming
Partha Pratim Paul
Lecturer, Dept. of ECE
Presidency University
2
Course Description
• Preface of computer programming;
• Structured programming basics;
• C fundamentals;
• Basic concept of data types, variables, operators, expressions,
statements, comparisons, loops;
• Basic searching and sorting algorithms;
• Data structures: array, structure, union, string, pointer and
memory allocation;
• Concept of function, recursion.
3
Course Objectives
To become familiar with the following items:-
4
Course Outline
Week Topics to be covered
1 Preface of computer programming; concept of data types;
Exploring variables, operators, expressions, statements,
2
comparisons
3 Working with LOOPS: FOR, DO..WHILE, WHILE;
4 Quiz and Midterm- I
5 basic searching and sorting algorithm: Bubble and Insertion Sort
6 Understanding Functions & Recursion
7 Intro to Array: 1D Array, 2D Array, 3D Array
8 Quiz and Midterm- II
9 Understanding Structure
10 Union & String: String Library, String Functions etc.
11 Pointer and memory allocation;
12 Problem Solving
Books
Text Books:
6
Marks Distribution
• Attendance: 10%
• Quiz + Mid Term : 20%+30%
• Final: 40%
7
Components of C Program
• C programs consists of one of more function, each of which
contains one or more statements;
8
General form of C program
Ret-type function-name(param-list)
{
Statement sequence
}
9
General form of C program
Function can be called by any name, any digit, any letter
(upper case-lower case) and underscore;
10
Simple Example of a Program
#include<stdio.h>
int main(void)
{
printf("This is a short C program.");
return 0;
}
11
Explanation of different functions and statements
{
}
12
Library Functions
13
Header File
#include<stdio.h>
Both upper and lower can be written but latter is the traditional
method.
14
Simple Example of a Program
#include<stdio.h>
int main(void)
{
printf("This is a short C program.");
return 0;
}
15
Simple Example of a Program
#include<stdio.h>
here stdio.h to be read by C compiler and to be included with the program. It
contains information related to the printf()
int main(void)
here main() function means where the C program or the program execution
begins. int specifies that main() returns an integer value.
and void means the compiler that main() does not have any parameters. Curly
brace means it’s a starting of statements.
{
printf("This is a short C program.");
it’s a statement. It calls the standard library funtion, printf()
return 0;
it causes main() to return the value zero. The value is returned to the calling
process.
}
16
Getting Started with Program
17
Getting Started with Program
# C Character Set
A character denotes any alphabet, digit or
special symbol used to represent information.
18
Getting Started with Program
# Constant, Variables and Keywords
A constant is an entity that doesn’t change but variable is an
entity that may change.
If x=3, and later x=5, then x=5 will be stored in the location.
19
C Constant
20
C Constant
21
C Constant
22
C Constant
• If the number is EXPONENTIAL The exponential form of
representation of real constants is usually used if the value of the constant is
either too small or too large.
23
Character Constant
24
Variable
25
Keywords
26
A C program
#include<stdio.h>
int main( )
int p, n ;
float r, si ;
p = 1000 ;
n=3;
r = 8.5 ;
printf ( "the simple interest is=%f", si) ; /* output of the simple interest */
27
Second C program
#include<stdio.h>
main( )
{
int p, n ;
float r, si ;
si = p * n * r / 100 ;
printf ( "the total simple interest is=%f" , si ) ;
}
28
Assignment - 01
1) Write a C program to find simple interest and the total
amount after calculating the simple interest.
END 29
Write a C program to calculate the total area and
circumference of a circle.
/* Write a C program to calculate the total area and circumference of a circle. */
#include<stdio.h>
int main( )
{
r=4; /* r=radius */
coc= 2*3.1416*r ;
printf ( "\nCircumference of Circle = %f" , coc ) ;
aoc= 3.1416*r*r ;
printf ( "\nArea of Circle = %f" , aoc ) ;
}
30
Write a C program to calculate the total area and
circumference of a circle.
/* Write a C program to calculate the total area and circumference of a circle. */
#include<stdio.h>
int main( )
{
float r, aoc, coc ;
coc= 2*3.1416*r ;
printf ( "\nCircumference of Circle = %f" , coc ) ;
aoc= 3.1416*r*r ;
printf ( "\\nArea of Circle = %f" , aoc ) ;
}
31