Vous êtes sur la page 1sur 23
APTITUDE TRAINING (Technical(Technical Part)Part) AtAt 66 thth SemesterSemester ofof GraduateGraduate ProgrammeProgramme
APTITUDE TRAINING
(Technical(Technical Part)Part)
AtAt 66 thth SemesterSemester ofof GraduateGraduate ProgrammeProgramme
inin allall BranchesBranches ofof EngineeringEngineering // TechnologyTechnology
InstructorInstructor :: Dr.Dr. SomsubhraSomsubhra Gupta,Gupta, ITIT Dept.Dept. JISCEJISCE
Venue:Venue: Dr.Dr. B.C.B.C. RoyRoy Auditorium.Auditorium.
Technical Aptitude Training JISCE
2015
1
TechnicalTechnical SessionSession LearningLearning Objective:Objective: •• ToTo bebe ableable toto identifyidentify
TechnicalTechnical SessionSession
LearningLearning Objective:Objective:
•• ToTo bebe ableable toto identifyidentify andand addressaddress basicbasic realreal worldworld problemsproblems
•• ToTo bebe ableable toto solvesolve themthem usingusing elementaryelementary CC programsprograms
•• ToTo bebe conversantconversant onon ElementaryElementary ProgrammingProgramming conceptconcept
SessionSession Plan:Plan:
C 1 C Basics
C 2 If statements
C 4 Functions
case
Output
C++ 1 Structures of C++ programming
C 6 Pointers
C 7 Structures
C 3 Loops
C 8 Arrays
C 9 Strings
C 5 Switch-
C 10 Input /
C++ 2 Basic Syntax Rules
C++ 3 Elementary I/O
C++ 4 Conditional Statements
LessonLesson Duration:Duration: 11 andand ½½ ourour each.each.
ExpectedExpected Outcome:Outcome: ToTo bebe ableable solvesolve problemsproblems byby writingwriting codescodes
Technical Aptitude Training JISCE
2015
2
TechnicalTechnical SessionSession ModeMode ofof Delivery:Delivery: •• AAuudiodio VisVisuualal throthrouughgh
TechnicalTechnical SessionSession
ModeMode ofof Delivery:Delivery:
•• AAuudiodio VisVisuualal throthrouughgh PoPowwerer PointPoint presentationpresentation (topic(topic wwise)ise)
•• DemonstrationDemonstration ofof programmersprogrammers usingusing anyany CC languagelanguage compilercompiler
•• ExplanationExplanation throughthrough MarkerMarker--WhiteWhite BoardBoard
TrainingTraining Plan:Plan:
•• DiscussionDiscussion ofof SessionSession topictopic inin briefbrief asas everyoneeveryone clearedcleared CC asas aa creditcredit coursecourse
inin 22 ndnd SemesterSemester ofof theirtheir resresppectiveective B.B. Tech.Tech. pproroggrammeramme
•• WritingWriting programsprograms onon BoardBoard // EditorEditor fromfrom previousprevious dayday assignmentsassignments
•• SolvingSolving weekweek--wisewise (all)(all) assignmentsassignments religiously.religiously.
•• EncouragingEncouraging contentcontent beyondbeyond assignments.assignments.
TrainingTraining EvaluationEvaluation ((inin selectiveselective sessions):sessions):
•• MCQMCQ questionquestion
•• CICI tectechhnniicacall testtest patternspatterns questquestiionsons
Technical Aptitude Training JISCE
2015
3
C Language Preliminaries • A C program contains one or more functions • main() is
C Language Preliminaries
• 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.ou
t
and
o
b
se ve
r
it
s
r
esu
lt
.
Technical Aptitude Training JISCE
2015
4
Identifiers • Begin with a letter or underscore: A-Z, a-z, _ • The rest of
Identifiers
• Begin with a letter or underscore: A-Z, a-z, _
• The rest of the name can be letters underscore or di its
,
,
g
• Guarantee that east least the first 8 characters are significant (those
come after the 8th character will be ignored) while most of C
compiler allows 32 significant characters.
Example:
_abc
ABC
Time time
_a1 abcdefgh
abcdefghi (may be the same as abcdefgh)
• Case sensitive
• Keywords: reserved names (lexical tokens)
auto
double
if
static
break else
int
c ar
struct
case entry
h
ex ern
t
reg s er
union do
i t
t
ype e
d f
return
go
sizeof
long switch
t
continue
fl
oa
Technical Aptitude Training JISCE
2015
5
Datatype Four Data Types (assume 2’s complement, byte machine) Data Type Abbreviation Size Range (byte)
Datatype
Four Data Types (assume 2’s complement, byte machine)
Data Type
Abbreviation
Size
Range
(byte)
char
char
1
-128 ~ 127
unsigned char
1
0 ~ 255
int
2
or 4
-2 15 ~ 2 15 -1 or -2 31 ~ 2 31 -1
unsigned int
unsigned
2
or 4
0 ~ 65535 or 0 ~ 2 32 -1
int
s or
h
t i
n
t
s or
h
t
2
-32768 ~ 32767
unsigned short int
unsigned short
2
0 ~ 65535
long int
long
4
-2 31 ~ 2 31 -1
unsi ned lon
g
g
int
unsi ned lon
g
g
4
0
~
2 32 1
-
float
4
double
8
Technical Aptitude Training JISCE
2015
6
Variable Declarations type v 1 ,v 2 ,v 3 , …, v n Example: int
Variable Declarations
type v 1 ,v 2 ,v 3 , …, v n
Example:
int i;
int j;
float k;
char c;
short int x;
long int y;
unsigned int z;
int a1, a2, a3, a4, a5;
Technical Aptitude Training JISCE
2015
7
Numeric, Character, String, Literals Literal Numeric literal fixed-point octal hexadecimal decimal int long
Numeric, Character, String, Literals
Literal
Numeric literal
fixed-point
octal
hexadecimal
decimal int
long (explicit)
O32 (= 24 D ) (covered later)
OxFE or Oxfe (=254 D ) (covered later)
32
32L or 32l
an ordinary integer literal that is too long to fit in an int is
also too long for long
floating-point
No single precision is used; always use double for literal
Example:
1.23
123.456e-7
0.12E
Technical Aptitude Training JISCE
2015
8
Numeric, Character, String, Literals Character literal (covered later) • American Standard Code for Information
Numeric, Character, String, Literals
Character literal (covered later)
• American Standard Code for Information Interchange (ASCII)
• Printable:
single space
‘0’ - ‘9’
‘A’ - ‘Z’
‘a’ - ‘z’
32
48 - 57
65 - 90
97 - 122
• Nonprintable and special meaning chars
‘\n’
10
‘\t’
9
‘\\’
new line
back slash
null
formfeed
double quote
9
‘\’’
39
‘\0’
0
‘\b’
8
‘\f’
12
’\r’
tab
single quote
back space
carriage return
13
‘\”’
34
‘\ddd’ arbitrary bit pattern using 1-3 octal digits
‘\Xdd’ for Hexadecimal mode
‘\017’ or ‘\17’
Shift-Ins, ^O
‘\04’ or ‘\4’ or ‘\004’ EOT (^D)
‘\033’ or ‘\X1B’
<esc>
Technical Aptitude Training JISCE
2015
9
Numeric, Character, String, Literals String Literal will be covered in Array section String is a
Numeric, Character, String, Literals
String Literal
will be covered in Array section
String is a array of chars but ended by ‘\0’
String literal is allocated in a continuous memory space
of Data Segment, so it can not be rewritten
Example:
“ABCD”
A
B C
D ‘\0’
4 chars but takes 5 byte spaces in memory
Question: “I am a string” takes ? Bytes
Ans: 13+1 = 14 bytes
Technical Aptitude Training JISCE
2015
10
Numeric, Character, String, Literals • Character literals & ASCII codes: char x; x=‘a’; /* x
Numeric, Character, 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
1 38
– if the code used is not ASCII code, one should check out each
value of character
Technical Aptitude Training JISCE
2015
11
Initialization If a variable is not initialized, the value of variable may be either 0
Initialization
If a variable is not initialized, the value of variable
may be either 0 or garbage depending on the storage
class of the variable.
int i=5;
float x=1.23;
char c=‘A’;
int i=1, j,k=5;
char c1 = ‘A’, c2 = 97;
float x=1.23, y=0.1;
Technical Aptitude Training JISCE
2015
12
Memory Concepts Each variable has a name, address, type, and value 1)int x; 2)scanf(“%d”, &x);
Memory Concepts
Each variable has a name, address, type, and value
1)int x;
2)scanf(“%d”, &x);
3) user inputs 10
4)x = 200;
After the execution of (1)
x
After the execution of (2) x
After the execution of (3) x
After the execution of (4) x
10
200
Previous value of x was overwritten
Technical Aptitude Training JISCE
2015
13
Sample Problems Write a program to take two numbers as input data and print their
Sample Problems
Write a program to take two numbers as input data and print their
sum, their difference, their product and their quotient.
Problem Inputs
float x, y;
problem Output
float sum;
/* two items */
/* 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 */
Technical Aptitude Training JISCE
2015
14
Sample Problems (Contd ) Pseudo Code: Declare variables of x and y; Prompt user to
Sample Problems (Contd )
Pseudo Code:
Declare variables of x and 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 not equal to zero, print the quotient of x divided by y
Technical Aptitude Training JISCE
2015
15
#include <stdio.h> int main(void) Exam le p p ro ram g { float x,y; float
#include <stdio.h>
int main(void)
Exam le
p
p
ro ram
g
{
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 sum of x and 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 quotient of x divided by y is:%f”,x/y);
else
printf(“\nquotient of x divided by y does not exist!\n”);
return(0);
}
Technical Aptitude Training JISCE
2015
16
Rule #1 Type conversion char, short → int float → double Rule #2 (double ←
Rule #1
Type conversion
char, short
int
float
double
Rule #2 (double ← long ← unsigned ← int)
If either operand is double, the other is converted to
double, and the result is double
Otherwise, if either operand is long, the other is
converted to long, and the result is long
Otherwise, if either operand is unsigned, the other is
converted to unsigned, and the result is unsigned
Otherwise, the operand must be int
Technical Aptitude Training JISCE
2015
17
Examples Example: c: char, u: unsigned, i: int, d: double, f:float, s: short, l: long,
Examples
Example: c: char,
u: unsigned, i: int, d: double, f:float,
s: short, l: long,
Expression
Final Data Type
Explanation
c
s
/
i
int
short→int, int/int, char→int, int-int
u
*
3 –
i
unsigned
int(3)→unsigned,
unsigned*unsigned=unsigned,
int→unsigned, unsigned-unsigned=unsigned
u
* 3.0 – i
double
c
+ i
int
unsigned→double, double*double,
int→double, double-double=double
char→int
c
+ 1.0
double
char→int (rule 1), int→double(rule 2)
3
* s
*
l
long
short→int, int*int, int→long, long*long
Technical Aptitude Training JISCE
2015
18
Note: Type conversion (contd ) 1. Conversion of int to long preserves sign, so does
Note:
Type conversion (contd )
1. Conversion of int to long preserves sign, so does
short
2.Var = expr
f = d; /*
round off */
i = f;
/* truncates fractions part, if the number is too big to fit, the
result is undetermined */
i = l; s = i; and c = i; /* may eliminate
high order bits */
Technical Aptitude Training JISCE
2015
19
3. If a specific type is required, the following syntax may be used, called cast
3. If a specific type is required, the following syntax may be used, called cast
operator.
(type) expr
Example:
float f=2.5;
x = (int)f + 1;
/* the result is 3, Q: will f value be changed? */
4. Unsigned int to int:
there is not actual conversion between int and unsigned int.
Example:(Assuming 2’s complement machine and int is 2 bytes long)
unsigned i = 65535; int j;
j
= i;
/* j will be –1
*/
j
= -2;
unsigned i = 1 + j;
/* i= 65535 */
Technical Aptitude Training JISCE
2015
20
Practice Code 1. Find average marks of Student 2. Greatest of 3 numbers using conditional
Practice Code
1. Find average marks of Student
2. Greatest of 3 numbers using conditional operator
3. Biggest of two numbers in C
4. Convert CM to feet and inches
5. Even or odd program in C
6. Simple interest calculation
7. Swapping of two Numbers
Technical Aptitude Training JISCE
2015
21
Assignment : Day 1 1. Write a Program to compute the summation up to a
Assignment : Day 1
1. Write a Program to compute the summation up to a number
2. Write a program to compute factorial of a given number
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
Technical Aptitude Training JISCE
2015
22