0% found this document useful (0 votes)
100 views31 pages

CS 101 Lecture 1 PDF

The document provides an overview of a computer programming course titled "Let Us C" that teaches the C programming language. The summary includes: - The course covers C fundamentals, data types, variables, operators, expressions, statements, comparisons, loops, basic searching and sorting algorithms, data structures like arrays and pointers, and functions and recursion. - The course objectives are to understand basics of programming, arrays/loops/data structures, functions/recursion/pointers, and developing algorithms. - The course outline lists weekly topics over 12 weeks including variables, loops, sorting, functions, arrays, structures, pointers, and problem solving.

Uploaded by

Mohammad Arafat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views31 pages

CS 101 Lecture 1 PDF

The document provides an overview of a computer programming course titled "Let Us C" that teaches the C programming language. The summary includes: - The course covers C fundamentals, data types, variables, operators, expressions, statements, comparisons, loops, basic searching and sorting algorithms, data structures like arrays and pointers, and functions and recursion. - The course objectives are to understand basics of programming, arrays/loops/data structures, functions/recursion/pointers, and developing algorithms. - The course outline lists weekly topics over 12 weeks including variables, loops, sorting, functions, arrays, structures, pointers, and problem solving.

Uploaded by

Mohammad Arafat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Let Us C

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:-

Understanding the basics of computer programming

Understanding the use of array, loops, and data structures.

Understanding the process of functions, recursions and


pointers.

Grasping the concept of developing algorithms and their


transformation into codes.

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:

1) Teach Yourself C by Herbert Schildt

2) Let Us C by Yashavant P. Kanetkar

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;

• A function is named sub-routine that can be called by other


parts of the program. Functions are building blocks of C;

• A statement specifies an action to be performed by the


program. They are the one responsible for performing the
operations;

• All C statements end with a semicolon;

8
General form of C program
Ret-type function-name(param-list)
{
Statement sequence
}

Ret-type specifies the type of data returned by the function. So it is


possible for a function to return a value;

Function is used to pass the information through its parameter list;

Statement sequence may consist one or more statements;

9
General form of C program
Function can be called by any name, any digit, any letter
(upper case-lower case) and underscore;

C is case-sensitive, so it can recognize the difference between


upper and lower case letters;

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

A C program may have different functions. But the only function


it must have is main();

main() function means where the program execution starts;


That means when the the program starts run, it starts executing
the statements inside main();

{
}

Program ends where the second bracket closed.

12
Library Functions

Library contains function to perform I/O, string, manipulating,


mathematical computations are usually referred as C standard
library.

It uses when program is compiled, code for each library function is


automatically included.

Example of library function is printf(). It is maintained between


brackets and double quote. When one or more characters are used
between double quotes are called as string.

In C program, library function is a statement, so it must be ended


with semicolon.

13
Header File

Common component of C programs are header files.

#include<stdio.h>

stdio.h are the common header files.

Both upper and lower can be written but latter is the traditional
method.

This line does not contain semi colon, becuase it itself a


instruction to the compiler, not defining any statement.

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.

Value stored in each locations, if constant are known as


constant.

If x=3, and later x=5, then x=5 will be stored in the location.

If x can store both the values 3 and 5, it is termed as


variable.

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 ;

si = p * n * r / 100 ; /* formula for simple interest */

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 ;

printf ( "Enter Amount of Principal = " ) ;


scanf ( "%d", &p ) ;

printf ( "Enter Number of Years = " ) ;


scanf ( "%d", &n ) ;

printf ( "Enter Rate of Interest = " ) ;


scanf ( "%f", &r ) ;

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.

2) Write a C program to calculate the total area and


circumference of a circle.

3) Write a C program to calculate sum of 5 courses and find


the total marks obtained and average.

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( )
{

float r, aoc, coc ;

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 ;

printf ( "Enter Radius = " ) ;


scanf ( "%f", &r ) ;

coc= 2*3.1416*r ;
printf ( "\nCircumference of Circle = %f" , coc ) ;

aoc= 3.1416*r*r ;
printf ( "\\nArea of Circle = %f" , aoc ) ;
}

31

You might also like