Professional Documents
Culture Documents
(Technical Part)
At 6th Semester of Graduate Programme
2015
Technical Session
Learning Objective:
To be able to identify and address basic real world problems
To be able to solve them using elementary C programs
To be conversant on Elementary Programming concept
Session Plan:
C 1 C Basics C 2 If statements C 3 Loops C 4 Functions
C 5 Switchcase C 6 Pointers C 7 Structures C 8 Arrays
C 9 Strings C 10 Input /
Output
C++ 1 Structures of C++ programming C++ 2 Basic Syntax Rules
C++ 3 Elementary
C
e e a y I/O
/O
C++ 4 Co
C
Conditional
d o a Statements
Sae e s
Lesson Duration: 1 and our each.
Expected Outcome: To be able solve problems by writing codes
Technical Aptitude Training JISCE
2015
Technical Session
Mode of Delivery:
Audio
A dio Vis
Visual
al thro
through
gh Po
Power
er Point presentation (topic wise)
ise)
Demonstration of programmers using any C language compiler
Explanation through MarkerMarker-White Board
Training Plan:
Discussion of Session topic in brief as everyone cleared C as a credit course
in 2nd Semester of their respective
p
B. Tech. p
programme
g
Writing programs on Board / Editor from previous day assignments
Solving week
week--wise (all) assignments religiously.
Encouraging content beyond assignments.
Training Evaluation (in
(in selective sessions):
MCQ question
CI technical
h i l test patterns questions
i
Technical Aptitude Training JISCE
2015
C Language Preliminaries
i i
i
A C program contains one or more functions
main() is the function name of your main (root) program
{ }: braces (left & right) to construct a block containing the
statements of a function
Every statement must end with a ;
\ is called an escape character
\n is an example of an escape sequence which indicates newline
Other escape sequences are: \t \r \a \\ \
Exercise: Use any editor to type and then save your first program
as main.c
% gcc main.c
a out
and observe its result.
result
% a.out
Technical Aptitude Training JISCE
2015
Id ifi
Identifiers
Case sensitive
Keywords: reserved names (lexical tokens)
auto
double
int
struct
char extern
return
union
if
static
break
case entry
long
register
typedef
do
go
sizeof
2015
else
switch
float
continue
5
Datatype
Four Data Types (assume 2s complement, byte machine)
Data Type
char
Abbreviation
Size
(byte)
Range
char
-128 ~ 127
unsigned char
0 ~ 255
2 or 4
2 or 4
0 ~ 65535 or 0 ~ 232-1
int
int
unsigned int
unsigned
short int
short
-32768
32768 ~ 32767
unsigned short
0 ~ 65535
long int
long
-231 ~ 231-1
unsigned long
0 ~ 2332-1
float
double
2015
V i bl D
Variable
Declarations
l
i
type v1,v2,v3, , vn
Example:
int i;
int j;
float k;
char c;
short int x;
long int y;
unsigned int z;
int a1, a2, a3, a4, a5;
2015
Literal
Numeric Character,
Numeric,
Character String,
String Literals
Numeric literal
fixed-point
octal
hexadecimal
decimal int
long (explicit)
2015
Numeric Character,
Numeric,
Character String,
String Literals
48 - 57
65 - 90
97 - 122
new line
back slash
null
formfeed
double quote
10
9
0
12
34
\t
\
\
\b
\r
tab
single
g quote
q
back space
carriage return
9
39
8
13
2015
Numeric Character,
Numeric,
Character String,
String Literals
String Literal
\0
...
2015
10
Numeric Character,
Numeric,
Character String,
String Literals
Character literals & ASCII codes:
char x;
x=a;
/* x = 97*/
Notes:
a and a are different; why?
a is the literal 97
a is an array of character literals, { a, \0} or {97, 0}
a + b +c is invalid but a+b+c = ? (hint: a = 97 in ASCII)
a + b + c = 97 + 98 + 99 = 294 = 256 + 38
in the memory
38
if the code used is not ASCII code,, one should check out each
value of character
Technical Aptitude Training JISCE
2015
11
I i i li i
Initialization
2015
12
Memory Concepts
10
200
2015
13
Sample Problems
Write a program to take two numbers as input data and print their
sum,, their difference,, their pproduct and their qquotient.
Problem Inputs
float x, y;
/* two items */
problem Output
float sum;
/* sum of x and y */
float difference; /* difference of x and y
*/
float product;
float quotient;
/* product of x and y */
/* quotient of x divided
by y */
2015
14
Pseudo Code:
Declare variables of x and y;
y
Prompt user to input the value of x and y;
Print the sum of x and y;
Print the difference of x and y;
Print the product of x and y;
If y nott equall to
t zero, print
i t the
th quotient
ti t off x divided
di id d by
b y
2015
15
Example program
#
#include
<stdio.h>
int main(void)
{
float x,y;
float sum;
printf(Enter the value of x:);
scanf(%f, &x);
printf(\nEnter the value of y:);
scanf(%f, &y);
sum = x + y;
printf(\nthe sum of x and y is:%f,sum);
printf(\nthe
printf(
\nthe sum of x and y is:%f,x+y);
is:%f ,x y);
printf(\nthe difference of x and y is:%f,x-y);
printf(\nthe product of x and y is:%f,x*y);
if (y != 0)
printf(\nthe
i tf(\ th quotient
ti t of
f x di
divided
id d b
by y i
is:%f,x/y);
%f / )
else
printf(\nquotient of x divided by y does not exist!\n);
return(0);
}
2015
16
R l #1
Rule
T
Type
conversion
i
char, short
float
Rule #2
int
double
2015
17
Examples
Example: c: char,
u: unsigned, i: int, d: double, f:float,
s: short,
, l: long,
g,
Expression
c s / i
u * 3 i
int
unsigned
Explanation
shortint, int/int, charint, int-int
int(3)unsigned
int(3)unsigned,
unsigned*unsigned=unsigned,
intunsigned, unsigned-unsigned=unsigned
u * 3.0 i
c + i
c + 1.0
1 0
3 * s * l
double
int
do ble
double
long
unsigneddouble, double*double,
double double,
intdouble, double-double=double
charint
char
h int
i t (rule
( l 1)
1), intdouble(rule
i td bl ( l 2)
shortint, int*int, intlong, long*long
2015
18
Note:
2015
19
3.
If a specific type is required, the following syntax may be used, called cast
operator.
(type) expr
Example:
float f=2
f=2.5;
5;
x = (int)f + 1;
/* the result is 3, Q: will f value be changed? */
4.
2015
20
PracticeCode
d
1.
2.
3.
4.
5.
6
6.
7.
Find
i d average marks
k off Student
d
Greatest of 3 numbers using conditional operator
Biggest
gg of two numbers in C
Convert CM to feet and inches
Even or odd program in C
Simple interest calculation
Swapping of two Numbers
2015
21
Assignment:Day1
1. Write a Program to compute the summation up to a number
2 Write
2.
W i a program to compute factorial
f
i l off a given
i
number
b
3. Write a program to compute sum of all the digits of a number
4. Write a program to compute whether a number is even or odd
5. Write a program to compute the mean, variance and standard
deviation from a list of number
2015
22