C++ Programming
in One Shot
11 Laptop/PC
2) Dedication
Chapter 1 : Basics
1) Basic Printing, n and endl wali cheez.
2) Variables, printing variables, int, float, and +,-,*,/ of integers.
3) Variable naming rules.
4) Comments
5) Taking Input
6) Modulus Operator
7) Float to int, int to float
8) Hierarchy
9) Char and ASCII
Basic program in C++
#include<iostream>
using namespace std;
int main(){
cout<<“hello world”;
}
Output
Hello World
How to move in next line?
Example :
cout<<”Hello PW”;
cout<<”Hello CW”;
Output will be :
Hello PWHello CW
'DRY RUN'
Out
·
Hello PW
a ⑧
-
- ·
Hello CW
~
Use of escape sequence endl and ‘n’
Example :
cout<<”Hello PW”;
cout<<endl;
cout<<”Hello CW”;
Output will be :
Hello PW
Hello CW
*
Athing:
1) Cont << Y;
2) Cont<< "Y";
3) cont < < 4+ 3;
1) Cont < < "4+3";
Variables and their Declaration
Let us focus on int data type as of now.
1) Variables as containers :
-
Boxer, Dabbe
Output
s
-
X
I
S
-
-
Printing Variables in C & Updation of Variables
int x = 5;
cout<<x<<endl;
x = 7;
cout<<x<<endl;
x = x + 6;
cout<<x<<endl;
x = x - 20;
cout<<x<<endl;
-
I Output
/
W
S
- / ·
I
X
r · 13
~ 7
= -
7
I
·
S
- x
=
x
-
20 0 =
7
-
x
=
13 - 20
v
~
-
↳ Output
- -
- ·S
X
-
tim
08
Arithmetic operations on int data type
int x = 5;
int y = 2;
cout<<x+y<<endl;
cout<<x-y<<endl;
cout<<x*y<<endl;
cout<<x/y<<endl; </ issue
W
~ Wk ·
7
x y - ·
3
W
~
·
10
~
~
intlnt I·
2
Increment - Decrement operators
int x = 5;
x<+;
cout<<x<<endl;
x<-;
cout<<x<<endl;
<+x;
cout<<x<<endl;
–-x;
cout<<x<<endl;
- Thodi
~
#45
der me
-
⑤S Output
-
X
6
w 6
-
I
S
-
~
S
-
~
~
Post Increment
put
v ·
Y
~
·U
v
-
a ·
S
X
-
Due increment
~
-
~
↳
·4
~
·
S
~ &
S
X
float data type
float x = 3.1;
Storing
- Real Numbers
Arithmetic operations on float data type
float x = 5;
float y = 2;
cout<<x+y<<endl;
cout<<x-y<<endl;
cout<<x*y<<endl;
cout<<x/y<<endl;
Example : Calculating Area of a Circle
- A
=
πr2
d
↓
area radius
3. 1415...
Example : Calculating Simple Interest
SI = PRT P
=
540 SA8. Y
float p;
00
100
2
=
32
float
wi
-
I
t =
3
100
-
S184
float ti sup +
32x3
To
-
float si;
= 318.4
Homework : Calculate Volume of a Sphere
Variable Naming rules
1) Variables can start from an alphabet or underscore _ or $ .
2) Special characters except _ and $ are not allowed.
3) Some particular keywords are not allowed.
4) Commas or blanks are not allowed.
Auto double int break extern enum unsigned while
case sizeof for const static long continue float
else signed do short switch char volatile default
goto struct if union return void register typedef
-
~
~
~
a
E
Variable Naming rules - Examples
Q. Which of the following are invalid variable names and why?
BASICSALARY _basic basic-hra
#MEAN group. 422
population in 2006 over time mindovermatter
FLOAT hELLO queue.
team’svictory Plot#3 2015_DDay
Taking input // Square of a Number
Take 2 numbers input from user and print their Sum
Modulus Operator 8-
5/3
-
aYob is remainder
3 IS
d
wea
is
divided
②5403
+, -
,,1,% by b
-> x
=
S x +
y
=
8
=
2
-y
=
3 x-
y
xxy
=
IS
x/y
=
1
x%y =
2
Modulus Operator ->
importance
is
divisibility
2%8 =
2
Some impant pants:
i) aYob =
a [it a<b>
2) Goa
=
0
3) aY)-b) =
aYob
4) (- a)%b =
-
(a%b]
Typecasting
Ques : Take integer ‘x’ as input and print
half of the number.
->
float tint, inte float
intx;
in x;
Hierarchy of operators
int i = 2 * 3 / 4 ;
cout<<i;
a
very important (BOD MAS)
↓
BY OP D, M/ A,S
L
Left
to
Right
#
(int)
i =
mate,an i =
2
*
3/4
=
6/4
=
2
*
0.75
=In
-D
Ii
=
2
*
3/4
6/4 = 2
*
0
- =
0X
char data type
char ch = ‘a’;
4 a, b, c... 2
A, B, C... 2
!D,H, $, %, v, 2, 1, 1, 2, 4, 3, "is -st, =, 2,3, 11, 2
·
?, I,,., , w
, 2
0,112, 3
... 9
ASCII values
char ch = ‘a’;
-very important [Typecasting]
65 ⑩8
297 B
+ 66
11's 49
b + 98
C3 67
1
199 I
S
I
/
de 100 /
S
/
: i =
90
'9'e57
!
2 + 122
MCQ Time !
Homework
In b = 6.6 / a + 2 * n ; which operation will be performed first?
(1) 6.6 / a
(2) a + 2
(3) 2 * n
(4) Depends upon compiler
MCQ
Which of the following statements is false
(1) Each new C++ instruction has to be written on a separate line
(2) Usually all C++ statements are entered in small case letters
(3) Blank spaces may be inserted between two words in a C++
statement
(4) Blank spaces cannot be inserted within a variable name
FALSE
TRUE
TRVE
TRUE
Homework
The expression, a = 7 / 22 * ( 3.14 + 2 ) * 3 / 5 ; evaluates to
(1) 8.28
(2) 6.28
(3) 3.14
(4) 0
C. W
.
-
float
d
f i
: i
a
=
7/22*
5.1443/5
-
i f
A
- a O
*
5.14
*
3/5
= i
~ =>) a - 043/S
=) a
=
Is
- C
=
0
Ketant:
float x
=
st
d
5/2 =
2
int 3.0/2 =
2.S
W 5/2.0
=
2.5
3.0/2.0
=
2.S
-
real no
no accept
MCQ
The expression x = 4 + 2 % - 8 evaluates to
(1) -6
(2) 6
(3) 4
(4) None of the above
1, 4,%7+,
-
->
x =
4 +
2 =
6
~ 2% -
8 =
2%8 =
2
a%(b) =
ajob
a%ob
=
a [acb)
**MCQ
What will be the value of d if d is a float after the operation
d = 2 / 7?
(1) 0
(2) 0.2857
(3) Cannot be determined
(4) None of the above
-> Homework
Chapter 2 : Conditionals
1) if, if - else
2) nested
3) Else if ladder
4) Ternary
5) switch
IF - ELSE
ans/output
situation dependent
↑
I
5522 ad
Ques : Take positive integer input and tell if it
is even or odd even
d
int ni
cinn; Is rm
=
0
it
1) Cont "Even"; C
it
=
0 even
2) Cont "Odd"; FO odd
-> a&b
d
a =
=
b,a! =
b
w Output
3
n
I Odd number
I W
I
Enter n:3
HW : Take positive integer input and tell if it is
divisible by 5 or not.
Ques : Take integer input and print the
absolute value of that integer +, -, x, 1, % Ari
OP
int ni
cin;
7 -> 7
==,! =, , ,
plate
10 - 10
if (n >
0) - cout<n -
21 - 21
else ecout-h;
*Ques : If cost price and selling price of an item is
input through the keyboard, write a program to
determine whether the seller has made profit or
incurred loss or no profit no loss. Also determine
how much profit he made or loss he incurred.
int up; it(sp> <p) profit s
sp-cp
in cp; It (cp <
sp) loss -
cp-sP
int sp; if (<p =
=
sp) to
no
cinsp; loss
-
HW : Given the length and breadth of a rectangle,
write a program to find whether the area of the
rectangle is greater than its perimeter.
e,b
d
A =
l* b;
4
=
24(l +
b);
Multiple Conditions
Using && and ||
and d
02
Ques : Take positive integer input and tell if it
is a three digit number or not.
if (n > 99 and n<1000) cont<< -
1
Ene
true
Ques : Take positive integer input and tell if it
is divisible by 5 and 3.
if (n%S
=
=
0 && n%3 =
=
0)
Ques : Take positive integer input and tell if it
is divisible by 5 or 3.
- 3, 6, 9, 12, 15, 18, 21, 24, 27,30...
- 5, 10, 15, 20, 25, 30, 39...
& 3, 5, 6, 9, 10, 12, 15, 18, 20, 21, 24, 25, 27, 31,
if (4%5
=
=
0 11 1903 ==
0) -
n
=
22
Ques : Take 3 numbers input and tell if they
can be the sides of a triangle. 20, and
a, b, c
if (19+ b) x and 12+ ap b and (c+
a) > b)
a
1
b
a+
b > c
b +
c = a
c +
a - b
Ques : Take 3 positive integers input and print
the greatest of them.
a, b, c
it (as b and a sc) cont<< a..
else if (b> a && b, c) cont<< b
else contC
Homework : Take 3 positive integers input and
print the least of them.
HW : Take positive integer input and tell if it is
divisible by 5 or 3 but not divisible by 15.
if ((n%s =
=
0 or 4%3 = =
0) and (n%/s!=
0))
Nested If - Else
if ( 12
it -
I else-
Esses
I
3
Ques : Take 3 positive integers input and print
the greatest of them. without
using multiple conditions
HW : If the ages of Ram, Shyam and Ajay are input
through the keyboard, write a program to
determine the youngest of the three.
Else If
Ques : Take input percentage of a student and
print the Grade according to marks:
1) 81-100 Very Good
2) 61-80 Good
3) 41-60 Average
4) <=40 Fail
HW : Given a point (x, y), write a program to find
out if it lies in the 1st Quadrant, 2nd Quadrant, 3rd
Quadrant, 4th Quadrant, on the x-axis, y-axis or at
the origin, viz. (0, 0).
I
I
⑧ ⑧
④
⑳ ⑧
-
I IV
-
-
⑧
⑧
Ternary Operator
expression 1 ? expression 2 : expression 3
if-die but
cool banneke liye
d lines bachana
⑨
Switch Statement
another
replacement
for it-else
↓
useless
switch ( integer expression ) {
case constant 1 :
do this ;
case constant 2 :
do this ;
case constant 3 :
do this ;
default :
do this ;
}
Syax: character int
I ↑
n1, n2, op
int Char
Radar's
Recommendation · exam se I
day before
-
Ques : Write a program to create a calculator that
performs basic arithmetic operations (add,
subtract, multiply and divide) using switch case
and functions. The calculator should input two
numbers and an operator from user.
=
int a;
int bi
charch;et,-, 1, A
-> achb
=>
n)
op n2
MCQ Time !
Predict the output
main( ) {
int x = 10, y = 20 ;
if ( x == y ) ;
cout<<x<<” “<<y ;
}
Output
~ ↳
I
10 20
~
HW : Predict the output
int main( ) {
int x = 3, y = 5 ;
if ( x == 3 )
printf ( "n%d", x ) ;
else ;
printf ( "n%d", y ) ;
}
->
=
I (out xendl;
=> couty endl;
*Predict the output
main( ) {
int x = 3, y, z ;
y = x = 10 ;
z = x < 10 ;
cout<<x<<” ”<<y<<” “<<z ;
}
- W
out
~ X y z
~ (Right
to
Left)
v
true->/
10 O
I
10 10 O
↳ false - 0
Chapter 3 : LOOPS
1) For Loop
2) Break and Continue
3) While and Do While Loop
4) Questions using Operators
5) Pattern Printing Problems
->
repetition
What and
Why?
baar hello world
For Loop
for(int i = 1; i<10; i++){
// code
}
tion int x =
3;
condi
↑ int i =
1;
↓
declaration +
initilization
1
increment
decrement
-
Iterator
Ques : Print hello world ‘n’ times. Take ‘n’ as
input from user Done!
How for loop works : the various parameters.
n
=
3
Initialization
Steps "
-
-
1) Check condition
·
Hello World 3) Increment
W I*
Output
23 Work
Y
M
·
Hello World
3
2 ·
Hello World
/
I
i
Ques : Print numbers from 1 to 100
using for look
Ques : Print all the even numbers from 1 to 100
↓
it (1%2 =
=
0) even
Method-2:
e
HW : Print all the odd numbers from 1 to 100
Ques : Print the table of 19.
↓
19, 38, 57, 76, 95, 114, 133, 152, 171, 190
HW : Print the table of ‘n’. Here ‘n’ is a integer
which user will input.
Ques : Display this AP - 1,3,5,7,9.. upto ‘n’
terms. -
Method-
1 ! nth term formula
-
->
an
=
a +
(n-
1)d
=>
an =
1 +
(n-1)2
=>
an
=
1+ 2n-2
=>
an=
27-1
Ques : Display this AP - 1,3,5,7,9.. upto ‘n’
terms.
4, 7, 10, 13....
-
-
-
rounds
&
Method- 2:
Using extra variable &
keeping'only for the iterations
- -
-
HW : Display this AP - 4,7,10,13,16.. upto ‘n’
terms.
~
a
=
4,d
=
3
an
=
a +
(n -
1)d
an =
4 +
(n-
1).3
an
=
4 +
3n -
3
an
=
3n+ 1
⑳34n
+
1
Ques : Display this GP - 1,2,4,8,16,32,.. upto ‘n’
terms. urvo
x2 x2 x2 x2
2x:
-> 5, 15, 4S, 135,
for lint i= 1,ic
=
n;i+
+)[
cont< a" ";
a =
a
+
2;
3
HW : Display this GP - 3,12,48,.. upto ‘n’ terms.
Break;
↓
thodi der me
ques he saath
Ques : WAP to find the highest factor of a
number ‘n’ (other than n itself)
24 - 1, 2, 3, 4, 6, 8, 12,24
↓
W
intf= 1; 1If me factor -
for lint i =1; i < m;i +
+
(
1 if (nii ==
0) f =
i;
3
Ques : WAP to check if a number is composite
or not.
it n has extra factor/factors except 1 & then it is
composite
d
if (n%i ==
0) - we found a
factor
L
-
mitt tnk
look -
Ques : WAP to check if a number is prime or
not.
dane
Continue;
d
if you
want
to
skipa
round
↓
print no. From 1 to
20 except
308
Ques : WAP to print odd numbers from 1 to
100.
Hiw.
-
using continue
While Loop
int i = 0;
while(i<10){
// code
i++;
}
- An alternate to for look
I
Kitni baal chalega, weird scenario
↓
multiple conditions
Do- While
Loop
do {
//code
} while ( another == 'y' ) ;
-eK baar kam se kam zun kane
Predict the output
int main( ) {
int x = 1 ;
while ( x == 1 )
x = x - 1 ;
cout<<x<<endl;
}
⑭
W
~
I
Predict the output
main( ) {
int i ;
while ( i = 10 ) {
cout<<i<<endl;
i = i + 1 ;
}
}
->
Infinite look
Predict the output
main( ) {
while ( 'a' < 'b' )
cout<< “malayalam is a palindrome" <<endl ;
}
1972983
Infinite look
HW : Predict the output
main( ) {
int i = 10 ;
while ( i = 20 )
printf ( "nA computer buff!" ) ;
}
HW : Predict the output
main( ) {
int x = 4, y = 0;
while ( x >= 0 ) {
x-- ;
y++ ;
if ( x == y )
continue ;
else
cout<<x<<” “<<y<<endl;
}
}
Questions using
Operators
+ - * / %
Ques : WAP to count digits of a given number.
-> intn; n =
5812
ein; int count =
0;
While (n>0) E
-
#Hint:1)
Integer division
I
n
=
n/10;
-
2) Divide in
by 10
again I count+t;
& again 3
Ques : WAP to count digits of a given number.
n = 123 Y count =
0
n = 123 count-1
n =
12 count= 2
n
=
1 count= 3
O C ~
n
=
0
count= 4
ans
finish
Ques : WAP to print sum of digits of a given
number.
n
=
1234 Sum =
12 +
3 + 4 =U
# Fit:1) Modulus (%) operator
2) 2%10 gives the last digit
3) 1 +
2+
3 +
y =
4 +
3 +
2 +
1
n
=
512843
Ques : WAP to print sum of digits of a given
number. 1 +
2+
3 +
y
=
4 +
3 +
2+
1 ed =
n%10
Algorithm:
e
n =
1234 ed =
Y Sum= 4
n = 123 3 7
12
2 9
I 1 10
⑧
look
finished
HW : WAP to print product of digits of a given
number. (There won't
be a zero in the number)
For ex: n = 1234
pro
=
12*3 *y =
24
HW : WAP to print sum of all the even digits of
a given number.
n =
1234
I 2 +
y
=
6
Ques : WAP to print reverse of a given
number.
A
n
=
1234 + 5
=
4321
#Hint: 1) sum of digits
2) 4321
=
0,0,4, 40, 43, 430, 432,4320,4321
Ques : WAP to print reverse of a given
number. v =
2 10
-
n =
153412/3 x 0 E
Algorithm r
=
r
+
ld
- 430/4328
~
=
0 44043 /432 - 4321
ed =
YBR 1
1) Id
2) 2
4 =
10
3)2 +
=
ld
4) n1=
16
HW : WAP to print the sum of given number
and its reverse.
n =
1234,2
=
4321
Ques : Print the factorial of a given number ‘n’.
-
Find the sum
from in ent
↳
5!
=
SX4x4X2x1
8!
=
8x 7 x6x5x4x3x2x1
n! =
nxn-Dx(n-2) . . . . 3 x2 x1
02
1x 2x3x4....(n-1)xh
HW : Print the factorials of first ‘n’ numbers
d
#Hint: n!
n
=
3,
11
=
I
2!
=
2x1
=
2
3=
3x2x1 =
6
4!
=
4x3x2x1
=
24
5!
=
Sx4x3x2x
=
120
HW : Write a program to print all the ASCII values
and their equivalent characters of 26 alphabets
using a while loop. 65
65 A 66
66B .
67C
90
I
:
90 Z
Pattern Printing
Questions
****
****
****
Chapter:4
-
nee
↓
Nested Looks
d
Nested it-else
L
ek ke andar ek
Ques : Print the given pattern
*****
*****
*****
Solid Rectangle
n ↓
-
mxy ka star rectange
I 1
m
=
2
M
n = 6
↓
* * *
* * X
& A & H Y A
Ques : Print the given pattern
****
****
****
****
Solid Square
Ques : Print the given pattern
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
Number Square
-n=
4
n
=
3
123
123
123
Homework: n =
S
- n=
Y n
=
2
111
- 1 11
33333
-ih
22
2222 2
44n4y
SSSSS
Ques : Print the given pattern
A B C D
A B C D
A B C D
A B C D
Alphabet Square
n =
4 n =
3
A BC
A
BC
A BC
HW:
1 HW: 2
- -
b
A
A A A
a c
(n =
3)
B BBB a b c
cc CC a b c
DDD D
Ques : Print the given pattern
*
**
***
****
Star Triangle
I 23 Y -j
I i
=
1,j =
1
1
2
jc
=
l
3
i
=
2,j =
1,2 E
Y i =
3,j
=
1,2,3
I i =
4,j
=
1,2,3,4
I
Ques : Print the given pattern
1
1 2
1 2 3
1 2 3 4
Number Triangle
-
-
H. W.
Number
-
Square - j =
=
u
d
code
jc
=
i
HW : Print the given pattern
A
A B
A B C
A B C D
Alphabet Triangle
I- row no.
- jecol no.
I ne no.
of rows
HW:
22
I
m
=
no.
of cols
333
AX X 123 I 1
yyy Y
x X X 123 222
*** 123 333
↳ I
A
BC
Seid
ABC -
A
BC
*HW : Print the given pattern
1
A B
1 2 3
A B C D
1 2 3 4 5
Alphabet Triangle
n
=
S
n
=
3
I
A B
I 2 3
#
Hint: If else
-
Ques : Print the given pattern
****
***
**
*
Star Triangle Ulta
↓
I I 234sj
I
i =
1, j
=
1,2,3,4
2
i
=
2,j =
1,2,3
-
it
jmax =
n+1
3
Y
i
=
3ej =
1,2
=> Imax =
n+ 1 -
i
i =
4,1j=
1
I *
-1-
i
2* *
E
3 a* * jc
=
1
y * * * a
HW : Print the given pattern
1 2 3 4
1 2 3
1 2
1
Number Triangle Ulta
H.W.
M.W.
I 1 I I
Y
and 22
2
and 93
3 3 432
432 I
4
HW : Print the given pattern
Alphabet Triangle Ulta
A B C D
A B C
A B
A
Ques : Print the given pattern
1
1 3
1 3 5
1 3 5 7
Odd Number Triangle
1 2 3 4 -
j
I
! 2
-> 13579...
AP W
2
1 2 3
3 1 2 3 Y
i
du
i jus
*Ques : Print the given pattern
1
2 3
4 5 6
7 8 9 10
Floyd’s Triangle
24
I 3 ej
I
2 n
=
2
3 I
23
Y
↓
n=
4
I
*Ques : Print the given pattern
1
0 1
1 0 1
0 1 0 1
0 & 1 Triangle
I 2 345+ j
when
I
(i+j7%2 =
=
0 - 1
2
else -0
3
Y
S I 0 10 I
Ques : Print the given pattern
*
*
*****
*
*
Star Plus
n
=
odd
12345 -j
1 ## ## it(i=
=
311j =
=
3) - x
2 # # #
#
else - #
4
## #
# n
=
3
S ## #
# #
A I
↓ * **
I n=
S #
a #
HW : Print the given pattern
******
* *
* *
******
Hollow Rectangle
I 23456 -
j
I
2
stars -
first now
- - -
-
i
- - last sow
first
col
d
last
col
i
HW : Print the given pattern
* *
* *
*
* *
* *
Star Cross
modd
- -
- - -
-
- -
-
-
- -
- -
*Ques : Print the given pattern
*
**
***
****
Star Triangle Reverse
↓
I look me ander 2 looks
I I D
--- I - -
2
2 2 * X
- -
3 -
-
3
-
-
t
3 x x x
-
4
y ya x ax
HW : Print the given pattern
1
1 2
1 2 3
1 2 3 4
Number Triangle Reverse
HW : Print the given pattern
Alphabet Triangle Reverse
A
A B
A B C
A B C D
HW : Print the given pattern
****
****
****
****
Rhombus
I X & & X
I
I -
-
2
- - -
2 - -
t
2
x x x &
- -
- 3 x a x a
3 -
Y &
-
Y x & & &
y
*Ques : Print the given pattern
*
***
*****
*******
Star Pyramid
HW : Print the given pattern
Number Pyramid
1
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7
HW : Print the given pattern
Alphabet Pyramid
A
A B C
A B C D E
A B C D E F G
**Ques : Print the given pattern
*
***
*****
*******
*****
***
*
Star Diamond
Recommend !
College Wallah Youtube Channel
-
d
playlists
d
c
Programming
Course
↓
Lecture 4-PP
L
Badiya (Tough)
Functions
What and
Why?
DRY
as not repeat yourself
d
1) to tackle repetition
2) There are certainpeice of code that
we use a lot
of times
in
problem.
Basic syntax
fun(){
// code
}
Output
·
How are
you?
~-
·
Hey
~
I
·Good
Morning
~
function call ·
Good
Morning
of scall
·
How are
you?
main()
return ;
-> It cannot be called more than once
1Reyword jisse function ka khatma ho jaata
kind of like break;
Kaam ki baate :
1) main() ek hi baar aata hai.
2) Starts with main
3) unlimited functions
How functions work : ek ke andar doosra,
doosre ke andar teesra
Parameters:formal parameters/
-
↑ dabbe
Outat
7 90
- 7 90
a D
values
W W
I
·
Fetual parameters
I
I
Pass
by value
Return type : Sum function se samajte hai
72 9 d
Out
81 81
81
-
Learntake
integer
a, be Sum
I
Library functions
Squtt
<but()
min()
max()
pow (a,b) e
ab
Ques : Combination and Permutation
↓
In,
2 -> >
->
pr =
me!
"c =
a =
a)(byc)
⑱x (-
x!
↓
①
3
I
=
6xSx1 =15
·:u!"*- O
y!x2! ⑰x1x2x1
Ques : Pascal triangle ~ For Look, Pattern
printing
D
O 12345 ej Nested for roofs
0 I
I 1 I ,
I 2 I I 2 I
↳ 133 I I 33 1
Y 146y I I Y
I
S I S 10 10 S I I is
" S I
d
I
e;
Scope of variable
↓
that
Formal parameters and Actual Parameters
d
I ↓
actual values
Done v
that
variables
are
dabbe
passed
Ques : Swap 2 numbers
MI:
↳
X y temp
temp =
x
x
=
y
y
=
temp
Ques : Swap 2 numbers
M-2 - without
using extra variable
-
-
Y
2
+
Y
-
Lie
2 +
Y
2
X My
X
y
X y
=>
x =
x+
y
=>
y
=
x
-
y
I x
=
x -
y
Pass by value & Pass by reference
swap(x,3
Y
Output
12:45 W
~ x y temp &
~
~
↳ ↳
-
v
Pass by value
12
45
12
I
S
12 US
- X
y
12 YS
⑧
*Pointers
->
Y bytes
int x
=
2;
↳ E
int
I x
y
IIIIIIIIIIIIIII
ibyte
*Pointers
0x16....
int x
=
3; - i
ptr
I int* ptr
=
2 x; x
0x14
coutyptrendl;
0x1I
1
Access the value of of the variable whose address is
in the
pointer is
using dereference/I operator
*Pointers
Outfit
3
12
~ 23
X ptr
~
W ⑲
I
-
-
~
Ox1Y 0x26
~
W
↓
Pass by Reference
*Pointers
v
-
0x12 0x19
W
12 4S
⑭ in
&
v 1/ *a =
45 a b
temp
- 0x22 0x44 0x 90
-
~ 12
w
*
US
w ~ ~
⑧
Pass by Reference
0x12 0x19
I
-
Output
~ X
y
State TRUE or FALSE :
1) The same variable names can be used in different
functions without any conflict. YES!
State TRUE or FALSE :
2) Every called function must contain a return
statement.
3) A function may contain more than one return
statements.
avoid
FALSE
TRUE
State TRUE or FALSE :
5) A function may be called more than once from any
other function TRUE
Recursion
Function calling itself
↓
1) Repetition
2) Infinite Loop
Ques : Print n to 1 ->
print
in no point
↓
n =
S s
:
G
quintin-1
I
w
-- Output
↓ :3
~
-
↳
I
I
2
&
~
In
:
-
- I
Base Case -
condition
~ X out
-
- ⑳
:
3
~ ·
= I
·E
& o
~
v
⑧
2
b
S
-
Ques : Print 1 to n [Recursion]
↓
contnendl;
I
2 print (n+1)
"
:
C
Ques : Print 1 to n (after recursive call)
en
~
Without extra Parameter
Proper Dry Pun
men
-
Output
⑧
· Enter n :3
-
-
"
W ·
I
-
- I
-
-
! Is ·
a
⑧
X
⑧
.
3
3 -
X
⑧
⑯
↳
·
Ques : Print sum from 1 to n (Parameterised)
iw -
College Wallah
I
Playlist
↓
C
programming
↓
Lecture - 6 Recursion
↓
sum 1 to
N parameterised
Ques : Print sum from 1 to n (Return type)
E
-> n =
5
->
1+
2+
3+
4 +
5
=
15
+
-> 1 +
2 +
3 +
4+
3
=
5 +
4+
3+
2 +
1
=>
sum(r)
=
n +
..3
+
2 +
1
sum(n) =
n
+
sumi-1)
ofmorethe
Ques : Make a function which calculates the
factorial of n using recursion.
3!
=
5x4x3x2x1
-> n! =
nxn-xn-2x....3x2x)
-
n! =
ux(n -
1)!
d
fact(n)
=
n x
fact(n-1)
d
fact(1) =
1
Ques : Make a function which calculates the
factorial of n using recursion.
Tree
Diagram : 120
ener
fact( S C
2 24
n
=
3
S*
fact (4)
↓46
4 x
fact(3)
22
3 *
factfati
Ques : Make a function which calculates ‘a’
raised to the power ‘b’ using recursion.
a =
3
3" =
81
3
=
3x3x3 x3
I
b =
Y
-> a = axa xqx a... a
-
b times
->
ab =
a xab-
1
=>
pow(a,b)
=
a x
powla,b-1)
-> base case e b =
0 ea:
1
*Multiple Calls
Ques : Write a function to calculate the nth
fibonacci number using recursion.
1123381321345589 . .
n
=
12345678
9 10 11
fibo(8)
=
fibo(z) +
fibols)
-> fibo(n)
=
fiboln-1) +
fiboln-2);
-> fibo() =
1
fibo(2) =
1
fibol
- ·
L 8 ↑
34 3
L fibo(s) + fibo(y)
3 - 2
1
fibolus Fiboli) Hottu
t
·
b0(2)
L
Gro
2
fibr+
Fibulz Fibiesfibores finisfied
L
11
fibo(2) +
Sibol Enterthe
tree
HW : Power function (logarithmic)
L
I -
⑳2
x
abz
X
8
a
= 28 =
24x24
2 -
2 x 2
2" =
22 x
22
27 =
2x26
- 22 =
2'xz
⑧
2
6
- 2x2
S
2' =
2x2
2 - 2x2
Y
z4 -
2x23
24 =
2x22
=
2x21
i 0
I 2 x 20
Arrays
DSA e data structures &
algorithms
1
data stone - variable -> intx;
What is an array?
d
I
List -> list
of integers e 11,76,13,88,46
list of char is A, B, A, C, F
list of float e 99.4,93.1,90.8,94.6, 50.S
el declaration se multiple dabbe band Santa noon.
Syntax and Declaration -
Indexing
0 I 2 3 Y
int x
(5];
X Y 2 6 -
2 10
x[0] =
4 e
initializing of array elements (individual)
x[1] =
2
x [4) =
10
x(2) =
6
x(3] = -
2
Accessing Elements of Array
↓ Very simple
using square brackets
arr [41;
Printing Output and Taking Input
using looks
Ques : Are the following array declarations correct?
int a (25) ;
int size = 10, b[size] ;
int c = {0,1,2} ;
X int a [25];
v
X intc(3)
=
20, 1, 23;
or
intc[1=
20,1,23;
int size =
10;
int b(size);
Ques : Which element of the array does this
expression reference?
num[4] int num [6];
d
4,
5th element from start
&
the 4th
index element
Memory Allocation in Arrays
Elllllllllllllll
int arr[3]=
24,3,23;
Passing Array to Functions
Reference
-
-
~
-
arrity
-
I
Output
w
-
Ques : Calculate the sum of all the elements in the
given array. 01 2 3 4 S
intavr[] =
[5, 1, 2, 4, 6,33;
↓
Sum
=
0;
G sum+=
arr[0];
sum+=
arr(1]
&
&
!
sum+=
arr[s];
Homework : Calculate the product of all the elements
in the given array.
Ques : Find the maximum value out of all the elements
in the array. 0 1 2 3 4
intarr[] =
[1,5,6,4,33;
-
intrx =
arr[O]; mx = 56
d
mx
=
max(mx, arr(i])
Homework : Find the minimum value out of all the
elements in the array.
HW : What is the difference between the 5’s in these
two expressions?
int num[5] ;
num[5] = 11 ;
1. first is particular element, second is type
2. first is array size, second is particular element
3. first is particular element, second is array size
4. both specify array size
unit,
State TRUE or FALSE :
1. The array int num[26] has twenty-six elements.
2. The expression num[1] designates the first element in
the array
3. It is necessary to initialize the array at the time of
declaration.
4. The expression num[27] designates the
twenty-eighth element in the array.
TRUE
FALSE
FALSE
TRUE
HW : Given an integer n. Create an array containing
squares of all natural numbers till n and print the
elements of the array.
-> int ni n
=
4
cinn;
↓
intains;
9/10
Ques : Given an array of integers, change the value of
all odd indexed elements to its second multiple and
increment all even indexed value by 10.
Homework;
-
>
01 2 3 Y
intarr(s) =
[1,2,3,4,53;
↳ ↳1, 4, 3,8,53
↳ [11, 4, 13,8,153
Ques : Count the number of elements in given array
greater than a given number x.
Homework
- -
-
-
intarr[] =
21,3, 0, 10, 2, 5, 63;
intx =
4;
int count= 0;
↳
if (arrlit,x) count++;
HW : Find the difference between the sum of elements
at even indices to the sum of elements at odd indices.
01 2 3 4 5 6
intaur)1=21,3,0,10,2,5,03;
sumeven=
9
sumOdd =
18
↳ 9 - 18 -
Ques : Find the second largest element in the given
Array.
intarr[] =
< 10, 1, 0,9, 4, 12, 1, 23;
int mx =
INT-MIN; my =
INN 1012
for (int i =
0; ic; it+ (2 smax:
EMIN 10
I mx =
max(mx, awr [i]);
3
int smax:
INT-MIN;
for (int :=
0:ic; it+d
I if (aw(i)! =
mx) smax =
max/Smax, aur[i]);
3
Ques : Write a program to copy the contents of one
array into another in the reverse order.
intads] =
3 1,2,3,4,53;a REALs
intb[S];
bit."
for (i=
0; ic=
4;i+
+
)[
i -
i =
n - 1- i;
i+
j =
n-
1
b(i)
=
a [s];
E
3 E-i
Ques : Write a program to reverse the array without
using any extra array.
01 2 3 4 i =
0;
intal] =
[5, 2, 3, 4, 13; j =
n-
1;
i
I
I
# Lit 1) Swap - a [i], al;]
2) Two variables
in;
Homework : If an array arr contains n elements, then
check if the given array is a palindrome or not.
arr=
[1, 2, 3, 4, 3, 2, 13 W
= >
E 1,2,3,3,2,13 w
=
[1,2,3,4,2,13 X
2D Arrays
10 students
1) Basics
Eddi
2) It Else
P CM E
3) Loope
4) PP
5) Function & Pointers
6) Revision
2) Arrays Array - list
2D
Arrays Away
Table
What and
Why?
So far we have explored arrays with only one dimension. It is also
possible for arrays to have two or more dimensions. The two
dimensional array is also called a matrix.
int arr[r][c];
This is a 2D array where r depicts number of rows in matrix and c
depicts number of columns in the matrix.
grid
ecolumns
↳ras
declaration.
e
↳ int arr[4][3]; int als): ,"I
alz] =
3
O 12
O
I
2 11 9 ->
ar(2]/2): 9
3 20
awe
↳
arr[3][T =
20
arr[2]/0]=11
int an [2][3];
O I 2 -j 612 64
O 6 I 2
-
435 13
G
I Y 35 2S
I
an [0][0] =
6 arr (1](0)
=
Y
aur (OIC1)
=
1 arr[1] [11: 3
arr [0](2):2
arr[1] (2):
3
Initialisation of a 2-Dimensional
Array
int arr[4][2] = { { 1234, 56 }, { 1256, 43 }, { 1434, 32 }, { 1312, 96 } } ;
int arr[4][2] = { 1234, 56 , 1256, 43 , 1434, 32 , 1312, 96} ;
int arr[2][3] = { 12, 34, 56, 78, 91, 23 } ;
int arr[ ][3] = {12, 34, 56, 78, 91, 23 } ;
2
2D
array -
array of away
intarr[333] =
[[1,2,33, (4,5,63,[7,8,933;
O 12
O I 2 3
I 436
2 I 89
aww
intaur (3[33:
(91,2,33,44,5,63,97,8,933;
int avr[][3]=
[1,2,3,4,5,6,7,8,93;
Ques : Write a program to store roll number and
marks obtained by 4 students side by side in a
matrix.
4 students -
Ragnar, Harsh, Sanket, Urvi
76 13 82 88
0 I 8 I
76 91 90
R O 16 81 0 I 2 3
H I
13 76 0 7613 82 88
S 2 82 al I 81
to 90
90
U
3 88 90
R U
Ques : Write a program to store 10 at every index of
a 2D matrix with 5 rows and 5 columns.
int aur [S][S];
0 12 3 Y
10 18
"" is
co
2 10 10 10 10 10
3 10 10 10 10
10
Y 10 10 10 10 10
Ques : Write a program to add two matrices.
Homework
- -
-
0 I 2
0 I 2 0 12
O 9 4 2 O 2 I 6 O 11 S S
t I
I O I 7 I 3 9 Y I S 10 11
a b C
-> cliJi):
a(i][] +
b(i][i];
Ques : Find the maximum element in a given
matrix. ↓
Ditto Same as ID
away
↓
int mx
=
INT-MIN;
busing nested look
traverse the entire ID
array
L
mx
=
max (mx, arr(i)(i));
HW : Find the minimum element in a given
matrix.
HW : Find the sum of all elements in a given
matrix. d
int sum
=
0;
↓
Sum+=
arr[i];];
HW : Find the product of all elements in a
given matrix.
int product: 1;
product x =
aur(i)(i);
HW : Given a matrix ‘a’ of dimension n x m and 2
coordinates (l1, r1) and (l2, r2). Return the sum of
the rectangle from (l1,r1) to (l2, r2).
O I 2 3 -j (11) and (4, 2)
O I 2 3 ↳
2
12
13 16
i=
1 to Y
I
I
S
9 10 11
3 7
13 17 19
4 8 17 18 20
-j =
1 to 2
I int a[8][4];
Ques : Write a program to Print the transpose
of the matrix entered by the user. -> create
d
AW
the
Already done 1 transpose
store it
Column Wise Prin
ting in a new
O I matrix
O I 2
O 7 2 3 0 I Y
->
I Y
S 6 I 2 S
2x3
3 6
2
3x2
2) Vector,
2D vector
2) DS A
L
Time & space complexity
Sorting, searching
DW I Linked list, stack, Quene, Trees, maps, Set, leaps
Graphs, DP, OOPS
skills
Decode 2.0 Batch - C++, DSA (Paid) Mrvi,
Sanket
PWskills &
College Wallah -
Playlist eC++&DSA
foundation course
Strings
1D Array raghar
I I
integer away
char
array (6):
float, Char E','hav
!
What are strings
and Why are
they used?
-> Char Arrays
L
questions
Declaration of Strings
and taking Input
string str;
~
strings:
"Raghav Garg",
d
↓
string si
getline/cin,s);
cins;
cout<<S;
Indexing of
characters in
Strings
strings:
"abc";
d sitic
strings:
"raghar";
cont << S90]://v
I
length)).
ASCII - O
"o'-hull character
cont<S;
d
Ques : Input a string of length n and count all
the vowels in the given string.
->
Updation of a
single character
in string
↓
Done
Ques : Input a string of size n and Update all
the even positions in the string to character
‘a’. Consider 0-based indexing.
H.W.
-
⑦@°=I>
-
-
012345678910
strings:
"Raghav Garg";
E aaahavaGara
Built-in string functions
d
STL
↓
standard template library
size() / length()
d
baat kar le hai
push_back() & append()
strings:"raghar";
pop_back() & clear()
string to empty string
“+” operator
reverse()
↓
strings:"raghar";
Ques : Input a string of even length and
reverse the first half of the string.
i I
012345
-> string s = "raghar";
-
↳ garhav
Ques : Input a string of length greater than 5 and
reverse the substring from position 2 to 5 using
inbuilt functions.
Homework
-
-
-
strings:
"raghar";
012345
↳
reverse (s. begin))+2, s. begin() +
1);
6
to_string() -> int to
string
d
int x
=
12345;
4
strings:
to-string(x);
Ques : Return the total number of digits in a
number without using any loop.
Hint : Try using inbuilt to_string() function.
x
=
91632
stoi
d
string =
"1412361";
intx =
stoils);
Thank you!
Maza aa
gay a

C++ in 10 Hours.pdf.pdf

  • 1.
    C++ Programming in OneShot 11 Laptop/PC 2) Dedication
  • 2.
    Chapter 1 :Basics 1) Basic Printing, n and endl wali cheez. 2) Variables, printing variables, int, float, and +,-,*,/ of integers. 3) Variable naming rules. 4) Comments 5) Taking Input 6) Modulus Operator 7) Float to int, int to float 8) Hierarchy 9) Char and ASCII
  • 3.
    Basic program inC++ #include<iostream> using namespace std; int main(){ cout<<“hello world”; } Output Hello World
  • 4.
    How to movein next line? Example : cout<<”Hello PW”; cout<<”Hello CW”; Output will be : Hello PWHello CW
  • 5.
    'DRY RUN' Out · Hello PW a⑧ - - · Hello CW ~
  • 6.
    Use of escapesequence endl and ‘n’ Example : cout<<”Hello PW”; cout<<endl; cout<<”Hello CW”; Output will be : Hello PW Hello CW
  • 7.
    * Athing: 1) Cont <<Y; 2) Cont<< "Y"; 3) cont < < 4+ 3; 1) Cont < < "4+3";
  • 8.
    Variables and theirDeclaration Let us focus on int data type as of now. 1) Variables as containers : - Boxer, Dabbe Output s - X I S - -
  • 9.
    Printing Variables inC & Updation of Variables int x = 5; cout<<x<<endl; x = 7; cout<<x<<endl; x = x + 6; cout<<x<<endl; x = x - 20; cout<<x<<endl; - I Output / W S - / · I X r · 13 ~ 7 = - 7 I · S - x = x - 20 0 = 7 - x = 13 - 20 v ~
  • 10.
    - ↳ Output - - -·S X - tim 08
  • 11.
    Arithmetic operations onint data type int x = 5; int y = 2; cout<<x+y<<endl; cout<<x-y<<endl; cout<<x*y<<endl; cout<<x/y<<endl; </ issue W ~ Wk · 7 x y - · 3 W ~ · 10 ~ ~ intlnt I· 2
  • 12.
    Increment - Decrementoperators int x = 5; x<+; cout<<x<<endl; x<-; cout<<x<<endl; <+x; cout<<x<<endl; –-x; cout<<x<<endl; - Thodi ~ #45 der me - ⑤S Output - X 6 w 6 - I S - ~ S - ~ ~
  • 13.
    Post Increment put v · Y ~ ·U v - a· S X - Due increment ~ - ~ ↳ ·4 ~ · S ~ & S X
  • 14.
    float data type floatx = 3.1; Storing - Real Numbers
  • 15.
    Arithmetic operations onfloat data type float x = 5; float y = 2; cout<<x+y<<endl; cout<<x-y<<endl; cout<<x*y<<endl; cout<<x/y<<endl;
  • 16.
    Example : CalculatingArea of a Circle - A = πr2 d ↓ area radius 3. 1415...
  • 17.
    Example : CalculatingSimple Interest SI = PRT P = 540 SA8. Y float p; 00 100 2 = 32 float wi - I t = 3 100 - S184 float ti sup + 32x3 To - float si; = 318.4
  • 18.
    Homework : CalculateVolume of a Sphere
  • 19.
    Variable Naming rules 1)Variables can start from an alphabet or underscore _ or $ . 2) Special characters except _ and $ are not allowed. 3) Some particular keywords are not allowed. 4) Commas or blanks are not allowed. Auto double int break extern enum unsigned while case sizeof for const static long continue float else signed do short switch char volatile default goto struct if union return void register typedef - ~ ~ ~ a E
  • 20.
    Variable Naming rules- Examples Q. Which of the following are invalid variable names and why? BASICSALARY _basic basic-hra #MEAN group. 422 population in 2006 over time mindovermatter FLOAT hELLO queue. team’svictory Plot#3 2015_DDay
  • 21.
    Taking input //Square of a Number
  • 22.
    Take 2 numbersinput from user and print their Sum
  • 23.
    Modulus Operator 8- 5/3 - aYobis remainder 3 IS d wea is divided ②5403 +, - ,,1,% by b -> x = S x + y = 8 = 2 -y = 3 x- y xxy = IS x/y = 1 x%y = 2
  • 24.
    Modulus Operator -> importance is divisibility 2%8= 2 Some impant pants: i) aYob = a [it a<b> 2) Goa = 0 3) aY)-b) = aYob 4) (- a)%b = - (a%b]
  • 25.
    Typecasting Ques : Takeinteger ‘x’ as input and print half of the number. -> float tint, inte float intx; in x;
  • 26.
    Hierarchy of operators inti = 2 * 3 / 4 ; cout<<i; a very important (BOD MAS) ↓ BY OP D, M/ A,S L Left to Right # (int) i = mate,an i = 2 * 3/4 = 6/4 = 2 * 0.75 =In -D Ii = 2 * 3/4 6/4 = 2 * 0 - = 0X
  • 27.
    char data type charch = ‘a’; 4 a, b, c... 2 A, B, C... 2 !D,H, $, %, v, 2, 1, 1, 2, 4, 3, "is -st, =, 2,3, 11, 2 · ?, I,,., , w , 2 0,112, 3 ... 9
  • 28.
    ASCII values char ch= ‘a’; -very important [Typecasting] 65 ⑩8 297 B + 66 11's 49 b + 98 C3 67 1 199 I S I / de 100 / S / : i = 90 '9'e57 ! 2 + 122
  • 29.
  • 30.
    Homework In b =6.6 / a + 2 * n ; which operation will be performed first? (1) 6.6 / a (2) a + 2 (3) 2 * n (4) Depends upon compiler
  • 31.
    MCQ Which of thefollowing statements is false (1) Each new C++ instruction has to be written on a separate line (2) Usually all C++ statements are entered in small case letters (3) Blank spaces may be inserted between two words in a C++ statement (4) Blank spaces cannot be inserted within a variable name FALSE TRUE TRVE TRUE
  • 32.
    Homework The expression, a= 7 / 22 * ( 3.14 + 2 ) * 3 / 5 ; evaluates to (1) 8.28 (2) 6.28 (3) 3.14 (4) 0 C. W . - float d f i : i a = 7/22* 5.1443/5 - i f A - a O * 5.14 * 3/5 = i ~ =>) a - 043/S =) a = Is - C = 0
  • 33.
    Ketant: float x = st d 5/2 = 2 int3.0/2 = 2.S W 5/2.0 = 2.5 3.0/2.0 = 2.S - real no no accept
  • 34.
    MCQ The expression x= 4 + 2 % - 8 evaluates to (1) -6 (2) 6 (3) 4 (4) None of the above 1, 4,%7+, - -> x = 4 + 2 = 6 ~ 2% - 8 = 2%8 = 2 a%(b) = ajob a%ob = a [acb)
  • 35.
    **MCQ What will bethe value of d if d is a float after the operation d = 2 / 7? (1) 0 (2) 0.2857 (3) Cannot be determined (4) None of the above -> Homework
  • 36.
    Chapter 2 :Conditionals 1) if, if - else 2) nested 3) Else if ladder 4) Ternary 5) switch
  • 37.
    IF - ELSE ans/output situationdependent ↑ I 5522 ad
  • 38.
    Ques : Takepositive integer input and tell if it is even or odd even d int ni cinn; Is rm = 0 it 1) Cont "Even"; C it = 0 even 2) Cont "Odd"; FO odd -> a&b d a = = b,a! = b
  • 39.
    w Output 3 n I Oddnumber I W I Enter n:3
  • 40.
    HW : Takepositive integer input and tell if it is divisible by 5 or not.
  • 41.
    Ques : Takeinteger input and print the absolute value of that integer +, -, x, 1, % Ari OP int ni cin; 7 -> 7 ==,! =, , , plate 10 - 10 if (n > 0) - cout<n - 21 - 21 else ecout-h;
  • 42.
    *Ques : Ifcost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss or no profit no loss. Also determine how much profit he made or loss he incurred. int up; it(sp> <p) profit s sp-cp in cp; It (cp < sp) loss - cp-sP int sp; if (<p = = sp) to no cinsp; loss -
  • 43.
    HW : Giventhe length and breadth of a rectangle, write a program to find whether the area of the rectangle is greater than its perimeter. e,b d A = l* b; 4 = 24(l + b);
  • 44.
  • 45.
    Ques : Takepositive integer input and tell if it is a three digit number or not. if (n > 99 and n<1000) cont<< - 1 Ene true
  • 46.
    Ques : Takepositive integer input and tell if it is divisible by 5 and 3. if (n%S = = 0 && n%3 = = 0)
  • 47.
    Ques : Takepositive integer input and tell if it is divisible by 5 or 3. - 3, 6, 9, 12, 15, 18, 21, 24, 27,30... - 5, 10, 15, 20, 25, 30, 39... & 3, 5, 6, 9, 10, 12, 15, 18, 20, 21, 24, 25, 27, 31, if (4%5 = = 0 11 1903 == 0) - n = 22
  • 48.
    Ques : Take3 numbers input and tell if they can be the sides of a triangle. 20, and a, b, c if (19+ b) x and 12+ ap b and (c+ a) > b) a 1 b a+ b > c b + c = a c + a - b
  • 49.
    Ques : Take3 positive integers input and print the greatest of them. a, b, c it (as b and a sc) cont<< a.. else if (b> a && b, c) cont<< b else contC
  • 50.
    Homework : Take3 positive integers input and print the least of them.
  • 51.
    HW : Takepositive integer input and tell if it is divisible by 5 or 3 but not divisible by 15. if ((n%s = = 0 or 4%3 = = 0) and (n%/s!= 0))
  • 52.
    Nested If -Else if ( 12 it - I else- Esses I 3
  • 53.
    Ques : Take3 positive integers input and print the greatest of them. without using multiple conditions
  • 54.
    HW : Ifthe ages of Ram, Shyam and Ajay are input through the keyboard, write a program to determine the youngest of the three.
  • 55.
  • 56.
    Ques : Takeinput percentage of a student and print the Grade according to marks: 1) 81-100 Very Good 2) 61-80 Good 3) 41-60 Average 4) <=40 Fail
  • 57.
    HW : Givena point (x, y), write a program to find out if it lies in the 1st Quadrant, 2nd Quadrant, 3rd Quadrant, 4th Quadrant, on the x-axis, y-axis or at the origin, viz. (0, 0). I I ⑧ ⑧ ④ ⑳ ⑧ - I IV - - ⑧ ⑧
  • 58.
    Ternary Operator expression 1? expression 2 : expression 3 if-die but cool banneke liye d lines bachana ⑨
  • 59.
  • 60.
    switch ( integerexpression ) { case constant 1 : do this ; case constant 2 : do this ; case constant 3 : do this ; default : do this ; } Syax: character int I ↑ n1, n2, op int Char Radar's Recommendation · exam se I day before -
  • 61.
    Ques : Writea program to create a calculator that performs basic arithmetic operations (add, subtract, multiply and divide) using switch case and functions. The calculator should input two numbers and an operator from user. = int a; int bi charch;et,-, 1, A -> achb => n) op n2
  • 62.
  • 63.
    Predict the output main() { int x = 10, y = 20 ; if ( x == y ) ; cout<<x<<” “<<y ; } Output ~ ↳ I 10 20 ~
  • 64.
    HW : Predictthe output int main( ) { int x = 3, y = 5 ; if ( x == 3 ) printf ( "n%d", x ) ; else ; printf ( "n%d", y ) ; } -> = I (out xendl; => couty endl;
  • 65.
    *Predict the output main() { int x = 3, y, z ; y = x = 10 ; z = x < 10 ; cout<<x<<” ”<<y<<” “<<z ; } - W out ~ X y z ~ (Right to Left) v true->/ 10 O I 10 10 O ↳ false - 0
  • 66.
    Chapter 3 :LOOPS 1) For Loop 2) Break and Continue 3) While and Do While Loop 4) Questions using Operators 5) Pattern Printing Problems -> repetition
  • 67.
  • 68.
    For Loop for(int i= 1; i<10; i++){ // code } tion int x = 3; condi ↑ int i = 1; ↓ declaration + initilization 1 increment decrement - Iterator
  • 69.
    Ques : Printhello world ‘n’ times. Take ‘n’ as input from user Done!
  • 70.
    How for loopworks : the various parameters. n = 3 Initialization Steps " - - 1) Check condition · Hello World 3) Increment W I* Output 23 Work Y M · Hello World 3 2 · Hello World / I i
  • 71.
    Ques : Printnumbers from 1 to 100 using for look
  • 72.
    Ques : Printall the even numbers from 1 to 100 ↓ it (1%2 = = 0) even Method-2: e
  • 73.
    HW : Printall the odd numbers from 1 to 100
  • 74.
    Ques : Printthe table of 19. ↓ 19, 38, 57, 76, 95, 114, 133, 152, 171, 190
  • 75.
    HW : Printthe table of ‘n’. Here ‘n’ is a integer which user will input.
  • 76.
    Ques : Displaythis AP - 1,3,5,7,9.. upto ‘n’ terms. - Method- 1 ! nth term formula - -> an = a + (n- 1)d => an = 1 + (n-1)2 => an = 1+ 2n-2 => an= 27-1
  • 77.
    Ques : Displaythis AP - 1,3,5,7,9.. upto ‘n’ terms. 4, 7, 10, 13.... - - - rounds & Method- 2: Using extra variable & keeping'only for the iterations - - -
  • 78.
    HW : Displaythis AP - 4,7,10,13,16.. upto ‘n’ terms. ~ a = 4,d = 3 an = a + (n - 1)d an = 4 + (n- 1).3 an = 4 + 3n - 3 an = 3n+ 1 ⑳34n + 1
  • 79.
    Ques : Displaythis GP - 1,2,4,8,16,32,.. upto ‘n’ terms. urvo x2 x2 x2 x2 2x: -> 5, 15, 4S, 135, for lint i= 1,ic = n;i+ +)[ cont< a" "; a = a + 2; 3
  • 80.
    HW : Displaythis GP - 3,12,48,.. upto ‘n’ terms.
  • 81.
  • 82.
    Ques : WAPto find the highest factor of a number ‘n’ (other than n itself) 24 - 1, 2, 3, 4, 6, 8, 12,24 ↓ W intf= 1; 1If me factor - for lint i =1; i < m;i + + ( 1 if (nii == 0) f = i; 3
  • 83.
    Ques : WAPto check if a number is composite or not. it n has extra factor/factors except 1 & then it is composite d if (n%i == 0) - we found a factor L - mitt tnk look -
  • 84.
    Ques : WAPto check if a number is prime or not. dane
  • 85.
  • 86.
    Ques : WAPto print odd numbers from 1 to 100. Hiw. - using continue
  • 87.
    While Loop int i= 0; while(i<10){ // code i++; } - An alternate to for look I Kitni baal chalega, weird scenario ↓ multiple conditions
  • 88.
    Do- While Loop do { //code }while ( another == 'y' ) ; -eK baar kam se kam zun kane
  • 89.
    Predict the output intmain( ) { int x = 1 ; while ( x == 1 ) x = x - 1 ; cout<<x<<endl; } ⑭ W ~ I
  • 90.
    Predict the output main() { int i ; while ( i = 10 ) { cout<<i<<endl; i = i + 1 ; } } -> Infinite look
  • 91.
    Predict the output main() { while ( 'a' < 'b' ) cout<< “malayalam is a palindrome" <<endl ; } 1972983 Infinite look
  • 92.
    HW : Predictthe output main( ) { int i = 10 ; while ( i = 20 ) printf ( "nA computer buff!" ) ; }
  • 93.
    HW : Predictthe output main( ) { int x = 4, y = 0; while ( x >= 0 ) { x-- ; y++ ; if ( x == y ) continue ; else cout<<x<<” “<<y<<endl; } }
  • 94.
  • 95.
    Ques : WAPto count digits of a given number. -> intn; n = 5812 ein; int count = 0; While (n>0) E - #Hint:1) Integer division I n = n/10; - 2) Divide in by 10 again I count+t; & again 3
  • 96.
    Ques : WAPto count digits of a given number. n = 123 Y count = 0 n = 123 count-1 n = 12 count= 2 n = 1 count= 3 O C ~ n = 0 count= 4 ans finish
  • 97.
    Ques : WAPto print sum of digits of a given number. n = 1234 Sum = 12 + 3 + 4 =U # Fit:1) Modulus (%) operator 2) 2%10 gives the last digit 3) 1 + 2+ 3 + y = 4 + 3 + 2 + 1 n = 512843
  • 98.
    Ques : WAPto print sum of digits of a given number. 1 + 2+ 3 + y = 4 + 3 + 2+ 1 ed = n%10 Algorithm: e n = 1234 ed = Y Sum= 4 n = 123 3 7 12 2 9 I 1 10 ⑧ look finished
  • 99.
    HW : WAPto print product of digits of a given number. (There won't be a zero in the number) For ex: n = 1234 pro = 12*3 *y = 24
  • 100.
    HW : WAPto print sum of all the even digits of a given number. n = 1234 I 2 + y = 6
  • 101.
    Ques : WAPto print reverse of a given number. A n = 1234 + 5 = 4321 #Hint: 1) sum of digits 2) 4321 = 0,0,4, 40, 43, 430, 432,4320,4321
  • 102.
    Ques : WAPto print reverse of a given number. v = 2 10 - n = 153412/3 x 0 E Algorithm r = r + ld - 430/4328 ~ = 0 44043 /432 - 4321 ed = YBR 1 1) Id 2) 2 4 = 10 3)2 + = ld 4) n1= 16
  • 103.
    HW : WAPto print the sum of given number and its reverse. n = 1234,2 = 4321
  • 104.
    Ques : Printthe factorial of a given number ‘n’. - Find the sum from in ent ↳ 5! = SX4x4X2x1 8! = 8x 7 x6x5x4x3x2x1 n! = nxn-Dx(n-2) . . . . 3 x2 x1 02 1x 2x3x4....(n-1)xh
  • 105.
    HW : Printthe factorials of first ‘n’ numbers d #Hint: n! n = 3, 11 = I 2! = 2x1 = 2 3= 3x2x1 = 6 4! = 4x3x2x1 = 24 5! = Sx4x3x2x = 120
  • 106.
    HW : Writea program to print all the ASCII values and their equivalent characters of 26 alphabets using a while loop. 65 65 A 66 66B . 67C 90 I : 90 Z
  • 107.
  • 108.
    Ques : Printthe given pattern ***** ***** ***** Solid Rectangle n ↓ - mxy ka star rectange I 1 m = 2 M n = 6 ↓ * * * * * X & A & H Y A
  • 109.
    Ques : Printthe given pattern **** **** **** **** Solid Square
  • 110.
    Ques : Printthe given pattern 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 Number Square -n= 4 n = 3 123 123 123
  • 111.
    Homework: n = S -n= Y n = 2 111 - 1 11 33333 -ih 22 2222 2 44n4y SSSSS
  • 112.
    Ques : Printthe given pattern A B C D A B C D A B C D A B C D Alphabet Square n = 4 n = 3 A BC A BC A BC
  • 113.
    HW: 1 HW: 2 -- b A A A A a c (n = 3) B BBB a b c cc CC a b c DDD D
  • 114.
    Ques : Printthe given pattern * ** *** **** Star Triangle I 23 Y -j I i = 1,j = 1 1 2 jc = l 3 i = 2,j = 1,2 E Y i = 3,j = 1,2,3 I i = 4,j = 1,2,3,4 I
  • 115.
    Ques : Printthe given pattern 1 1 2 1 2 3 1 2 3 4 Number Triangle - - H. W. Number - Square - j = = u d code jc = i
  • 116.
    HW : Printthe given pattern A A B A B C A B C D Alphabet Triangle
  • 117.
    I- row no. -jecol no. I ne no. of rows HW: 22 I m = no. of cols 333 AX X 123 I 1 yyy Y x X X 123 222 *** 123 333 ↳ I A BC Seid ABC - A BC
  • 118.
    *HW : Printthe given pattern 1 A B 1 2 3 A B C D 1 2 3 4 5 Alphabet Triangle n = S n = 3 I A B I 2 3 # Hint: If else -
  • 119.
    Ques : Printthe given pattern **** *** ** * Star Triangle Ulta ↓ I I 234sj I i = 1, j = 1,2,3,4 2 i = 2,j = 1,2,3 - it jmax = n+1 3 Y i = 3ej = 1,2 => Imax = n+ 1 - i i = 4,1j= 1 I * -1- i 2* * E 3 a* * jc = 1 y * * * a
  • 120.
    HW : Printthe given pattern 1 2 3 4 1 2 3 1 2 1 Number Triangle Ulta H.W. M.W. I 1 I I Y and 22 2 and 93 3 3 432 432 I 4
  • 121.
    HW : Printthe given pattern Alphabet Triangle Ulta A B C D A B C A B A
  • 122.
    Ques : Printthe given pattern 1 1 3 1 3 5 1 3 5 7 Odd Number Triangle 1 2 3 4 - j I ! 2 -> 13579... AP W 2 1 2 3 3 1 2 3 Y i du i jus
  • 123.
    *Ques : Printthe given pattern 1 2 3 4 5 6 7 8 9 10 Floyd’s Triangle 24 I 3 ej I 2 n = 2 3 I 23 Y ↓ n= 4 I
  • 124.
    *Ques : Printthe given pattern 1 0 1 1 0 1 0 1 0 1 0 & 1 Triangle I 2 345+ j when I (i+j7%2 = = 0 - 1 2 else -0 3 Y S I 0 10 I
  • 125.
    Ques : Printthe given pattern * * ***** * * Star Plus n = odd 12345 -j 1 ## ## it(i= = 311j = = 3) - x 2 # # # # else - # 4 ## # # n = 3 S ## # # # A I ↓ * ** I n= S # a #
  • 126.
    HW : Printthe given pattern ****** * * * * ****** Hollow Rectangle I 23456 - j I 2 stars - first now - - - - i - - last sow first col d last col i
  • 127.
    HW : Printthe given pattern * * * * * * * * * Star Cross modd - - - - - - - - - - - - - -
  • 128.
    *Ques : Printthe given pattern * ** *** **** Star Triangle Reverse ↓ I look me ander 2 looks I I D --- I - - 2 2 2 * X - - 3 - - 3 - - t 3 x x x - 4 y ya x ax
  • 129.
    HW : Printthe given pattern 1 1 2 1 2 3 1 2 3 4 Number Triangle Reverse
  • 130.
    HW : Printthe given pattern Alphabet Triangle Reverse A A B A B C A B C D
  • 131.
    HW : Printthe given pattern **** **** **** **** Rhombus I X & & X I I - - 2 - - - 2 - - t 2 x x x & - - - 3 x a x a 3 - Y & - Y x & & & y
  • 132.
    *Ques : Printthe given pattern * *** ***** ******* Star Pyramid
  • 133.
    HW : Printthe given pattern Number Pyramid 1 1 2 3 1 2 3 4 5 1 2 3 4 5 6 7
  • 134.
    HW : Printthe given pattern Alphabet Pyramid A A B C A B C D E A B C D E F G
  • 135.
    **Ques : Printthe given pattern * *** ***** ******* ***** *** * Star Diamond Recommend ! College Wallah Youtube Channel - d playlists d c Programming Course ↓ Lecture 4-PP L Badiya (Tough)
  • 136.
  • 137.
    What and Why? DRY as notrepeat yourself d 1) to tackle repetition 2) There are certainpeice of code that we use a lot of times in problem.
  • 138.
  • 139.
  • 140.
    main() return ; -> Itcannot be called more than once 1Reyword jisse function ka khatma ho jaata kind of like break;
  • 141.
    Kaam ki baate: 1) main() ek hi baar aata hai. 2) Starts with main 3) unlimited functions
  • 142.
    How functions work: ek ke andar doosra, doosre ke andar teesra
  • 143.
    Parameters:formal parameters/ - ↑ dabbe Outat 790 - 7 90 a D values W W I · Fetual parameters I I Pass by value
  • 144.
    Return type :Sum function se samajte hai 72 9 d Out 81 81 81 - Learntake integer a, be Sum I
  • 145.
  • 146.
    Ques : Combinationand Permutation ↓ In, 2 -> > -> pr = me! "c = a = a)(byc) ⑱x (- x! ↓ ① 3 I = 6xSx1 =15 ·:u!"*- O y!x2! ⑰x1x2x1
  • 147.
    Ques : Pascaltriangle ~ For Look, Pattern printing D O 12345 ej Nested for roofs 0 I I 1 I , I 2 I I 2 I ↳ 133 I I 33 1 Y 146y I I Y I S I S 10 10 S I I is " S I d I e;
  • 148.
  • 149.
    Formal parameters andActual Parameters d I ↓ actual values Done v that variables are dabbe passed
  • 150.
    Ques : Swap2 numbers MI: ↳ X y temp temp = x x = y y = temp
  • 151.
    Ques : Swap2 numbers M-2 - without using extra variable - - Y 2 + Y - Lie 2 + Y 2 X My X y X y => x = x+ y => y = x - y I x = x - y
  • 152.
    Pass by value& Pass by reference swap(x,3 Y Output 12:45 W ~ x y temp & ~ ~ ↳ ↳ - v Pass by value 12 45 12 I S 12 US - X y 12 YS ⑧
  • 153.
    *Pointers -> Y bytes int x = 2; ↳E int I x y IIIIIIIIIIIIIII ibyte
  • 154.
    *Pointers 0x16.... int x = 3; -i ptr I int* ptr = 2 x; x 0x14 coutyptrendl; 0x1I 1 Access the value of of the variable whose address is in the pointer is using dereference/I operator
  • 155.
    *Pointers Outfit 3 12 ~ 23 X ptr ~ W⑲ I - - ~ Ox1Y 0x26 ~ W ↓ Pass by Reference
  • 156.
    *Pointers v - 0x12 0x19 W 12 4S ⑭in & v 1/ *a = 45 a b temp - 0x22 0x44 0x 90 - ~ 12 w * US w ~ ~ ⑧ Pass by Reference 0x12 0x19 I - Output ~ X y
  • 157.
    State TRUE orFALSE : 1) The same variable names can be used in different functions without any conflict. YES!
  • 158.
    State TRUE orFALSE : 2) Every called function must contain a return statement. 3) A function may contain more than one return statements. avoid FALSE TRUE
  • 159.
    State TRUE orFALSE : 5) A function may be called more than once from any other function TRUE
  • 160.
  • 161.
    Function calling itself ↓ 1)Repetition 2) Infinite Loop
  • 162.
    Ques : Printn to 1 -> print in no point ↓ n = S s : G quintin-1 I w
  • 163.
  • 164.
    ~ X out - -⑳ : 3 ~ · = I ·E & o ~ v ⑧ 2 b S -
  • 165.
    Ques : Print1 to n [Recursion] ↓ contnendl; I 2 print (n+1) " : C
  • 166.
    Ques : Print1 to n (after recursive call) en ~ Without extra Parameter
  • 167.
    Proper Dry Pun men - Output ⑧ ·Enter n :3 - - " W · I - - I - - ! Is · a ⑧ X ⑧ . 3 3 - X ⑧ ⑯ ↳ ·
  • 168.
    Ques : Printsum from 1 to n (Parameterised) iw - College Wallah I Playlist ↓ C programming ↓ Lecture - 6 Recursion ↓ sum 1 to N parameterised
  • 169.
    Ques : Printsum from 1 to n (Return type) E -> n = 5 -> 1+ 2+ 3+ 4 + 5 = 15 + -> 1 + 2 + 3 + 4+ 3 = 5 + 4+ 3+ 2 + 1 => sum(r) = n + ..3 + 2 + 1 sum(n) = n + sumi-1)
  • 170.
  • 171.
    Ques : Makea function which calculates the factorial of n using recursion. 3! = 5x4x3x2x1 -> n! = nxn-xn-2x....3x2x) - n! = ux(n - 1)! d fact(n) = n x fact(n-1) d fact(1) = 1
  • 172.
    Ques : Makea function which calculates the factorial of n using recursion. Tree Diagram : 120 ener fact( S C 2 24 n = 3 S* fact (4) ↓46 4 x fact(3) 22 3 * factfati
  • 173.
    Ques : Makea function which calculates ‘a’ raised to the power ‘b’ using recursion. a = 3 3" = 81 3 = 3x3x3 x3 I b = Y -> a = axa xqx a... a - b times -> ab = a xab- 1 => pow(a,b) = a x powla,b-1) -> base case e b = 0 ea: 1
  • 174.
    *Multiple Calls Ques :Write a function to calculate the nth fibonacci number using recursion. 1123381321345589 . . n = 12345678 9 10 11 fibo(8) = fibo(z) + fibols) -> fibo(n) = fiboln-1) + fiboln-2); -> fibo() = 1 fibo(2) = 1
  • 175.
    fibol - · L 8↑ 34 3 L fibo(s) + fibo(y) 3 - 2 1 fibolus Fiboli) Hottu t · b0(2) L Gro 2 fibr+ Fibulz Fibiesfibores finisfied L 11 fibo(2) + Sibol Enterthe tree
  • 176.
    HW : Powerfunction (logarithmic) L I - ⑳2 x abz X 8 a = 28 = 24x24 2 - 2 x 2 2" = 22 x 22 27 = 2x26 - 22 = 2'xz ⑧ 2 6 - 2x2 S 2' = 2x2 2 - 2x2 Y z4 - 2x23 24 = 2x22 = 2x21 i 0 I 2 x 20
  • 177.
    Arrays DSA e datastructures & algorithms 1 data stone - variable -> intx;
  • 178.
    What is anarray? d I List -> list of integers e 11,76,13,88,46 list of char is A, B, A, C, F list of float e 99.4,93.1,90.8,94.6, 50.S el declaration se multiple dabbe band Santa noon.
  • 179.
    Syntax and Declaration- Indexing 0 I 2 3 Y int x (5]; X Y 2 6 - 2 10 x[0] = 4 e initializing of array elements (individual) x[1] = 2 x [4) = 10 x(2) = 6 x(3] = - 2
  • 180.
    Accessing Elements ofArray ↓ Very simple using square brackets arr [41;
  • 181.
    Printing Output andTaking Input using looks
  • 182.
    Ques : Arethe following array declarations correct? int a (25) ; int size = 10, b[size] ; int c = {0,1,2} ; X int a [25]; v X intc(3) = 20, 1, 23; or intc[1= 20,1,23; int size = 10; int b(size);
  • 183.
    Ques : Whichelement of the array does this expression reference? num[4] int num [6]; d 4, 5th element from start & the 4th index element
  • 184.
    Memory Allocation inArrays Elllllllllllllll int arr[3]= 24,3,23;
  • 185.
    Passing Array toFunctions Reference - - ~ - arrity - I Output w -
  • 186.
    Ques : Calculatethe sum of all the elements in the given array. 01 2 3 4 S intavr[] = [5, 1, 2, 4, 6,33; ↓ Sum = 0; G sum+= arr[0]; sum+= arr(1] & & ! sum+= arr[s];
  • 187.
    Homework : Calculatethe product of all the elements in the given array.
  • 188.
    Ques : Findthe maximum value out of all the elements in the array. 0 1 2 3 4 intarr[] = [1,5,6,4,33; - intrx = arr[O]; mx = 56 d mx = max(mx, arr(i])
  • 189.
    Homework : Findthe minimum value out of all the elements in the array.
  • 190.
    HW : Whatis the difference between the 5’s in these two expressions? int num[5] ; num[5] = 11 ; 1. first is particular element, second is type 2. first is array size, second is particular element 3. first is particular element, second is array size 4. both specify array size unit,
  • 191.
    State TRUE orFALSE : 1. The array int num[26] has twenty-six elements. 2. The expression num[1] designates the first element in the array 3. It is necessary to initialize the array at the time of declaration. 4. The expression num[27] designates the twenty-eighth element in the array. TRUE FALSE FALSE TRUE
  • 192.
    HW : Givenan integer n. Create an array containing squares of all natural numbers till n and print the elements of the array. -> int ni n = 4 cinn; ↓ intains; 9/10
  • 193.
    Ques : Givenan array of integers, change the value of all odd indexed elements to its second multiple and increment all even indexed value by 10. Homework; - > 01 2 3 Y intarr(s) = [1,2,3,4,53; ↳ ↳1, 4, 3,8,53 ↳ [11, 4, 13,8,153
  • 194.
    Ques : Countthe number of elements in given array greater than a given number x. Homework - - - - intarr[] = 21,3, 0, 10, 2, 5, 63; intx = 4; int count= 0; ↳ if (arrlit,x) count++;
  • 195.
    HW : Findthe difference between the sum of elements at even indices to the sum of elements at odd indices. 01 2 3 4 5 6 intaur)1=21,3,0,10,2,5,03; sumeven= 9 sumOdd = 18 ↳ 9 - 18 -
  • 196.
    Ques : Findthe second largest element in the given Array. intarr[] = < 10, 1, 0,9, 4, 12, 1, 23; int mx = INT-MIN; my = INN 1012 for (int i = 0; ic; it+ (2 smax: EMIN 10 I mx = max(mx, awr [i]); 3 int smax: INT-MIN; for (int := 0:ic; it+d I if (aw(i)! = mx) smax = max/Smax, aur[i]); 3
  • 197.
    Ques : Writea program to copy the contents of one array into another in the reverse order. intads] = 3 1,2,3,4,53;a REALs intb[S]; bit." for (i= 0; ic= 4;i+ + )[ i - i = n - 1- i; i+ j = n- 1 b(i) = a [s]; E 3 E-i
  • 198.
    Ques : Writea program to reverse the array without using any extra array. 01 2 3 4 i = 0; intal] = [5, 2, 3, 4, 13; j = n- 1; i I I # Lit 1) Swap - a [i], al;] 2) Two variables in;
  • 199.
    Homework : Ifan array arr contains n elements, then check if the given array is a palindrome or not. arr= [1, 2, 3, 4, 3, 2, 13 W = > E 1,2,3,3,2,13 w = [1,2,3,4,2,13 X
  • 200.
    2D Arrays 10 students 1)Basics Eddi 2) It Else P CM E 3) Loope 4) PP 5) Function & Pointers 6) Revision 2) Arrays Array - list 2D Arrays Away Table
  • 201.
    What and Why? So farwe have explored arrays with only one dimension. It is also possible for arrays to have two or more dimensions. The two dimensional array is also called a matrix. int arr[r][c]; This is a 2D array where r depicts number of rows in matrix and c depicts number of columns in the matrix. grid ecolumns ↳ras
  • 202.
    declaration. e ↳ int arr[4][3];int als): ,"I alz] = 3 O 12 O I 2 11 9 -> ar(2]/2): 9 3 20 awe ↳ arr[3][T = 20 arr[2]/0]=11
  • 203.
    int an [2][3]; OI 2 -j 612 64 O 6 I 2 - 435 13 G I Y 35 2S I an [0][0] = 6 arr (1](0) = Y aur (OIC1) = 1 arr[1] [11: 3 arr [0](2):2 arr[1] (2): 3
  • 204.
    Initialisation of a2-Dimensional Array int arr[4][2] = { { 1234, 56 }, { 1256, 43 }, { 1434, 32 }, { 1312, 96 } } ; int arr[4][2] = { 1234, 56 , 1256, 43 , 1434, 32 , 1312, 96} ; int arr[2][3] = { 12, 34, 56, 78, 91, 23 } ; int arr[ ][3] = {12, 34, 56, 78, 91, 23 } ; 2 2D array - array of away
  • 205.
    intarr[333] = [[1,2,33, (4,5,63,[7,8,933; O12 O I 2 3 I 436 2 I 89 aww intaur (3[33: (91,2,33,44,5,63,97,8,933; int avr[][3]= [1,2,3,4,5,6,7,8,93;
  • 206.
    Ques : Writea program to store roll number and marks obtained by 4 students side by side in a matrix. 4 students - Ragnar, Harsh, Sanket, Urvi 76 13 82 88 0 I 8 I 76 91 90 R O 16 81 0 I 2 3 H I 13 76 0 7613 82 88 S 2 82 al I 81 to 90 90 U 3 88 90 R U
  • 207.
    Ques : Writea program to store 10 at every index of a 2D matrix with 5 rows and 5 columns. int aur [S][S]; 0 12 3 Y 10 18 "" is co 2 10 10 10 10 10 3 10 10 10 10 10 Y 10 10 10 10 10
  • 208.
    Ques : Writea program to add two matrices. Homework - - - 0 I 2 0 I 2 0 12 O 9 4 2 O 2 I 6 O 11 S S t I I O I 7 I 3 9 Y I S 10 11 a b C -> cliJi): a(i][] + b(i][i];
  • 209.
    Ques : Findthe maximum element in a given matrix. ↓ Ditto Same as ID away ↓ int mx = INT-MIN; busing nested look traverse the entire ID array L mx = max (mx, arr(i)(i));
  • 210.
    HW : Findthe minimum element in a given matrix.
  • 211.
    HW : Findthe sum of all elements in a given matrix. d int sum = 0; ↓ Sum+= arr[i];];
  • 212.
    HW : Findthe product of all elements in a given matrix. int product: 1; product x = aur(i)(i);
  • 213.
    HW : Givena matrix ‘a’ of dimension n x m and 2 coordinates (l1, r1) and (l2, r2). Return the sum of the rectangle from (l1,r1) to (l2, r2). O I 2 3 -j (11) and (4, 2) O I 2 3 ↳ 2 12 13 16 i= 1 to Y I I S 9 10 11 3 7 13 17 19 4 8 17 18 20 -j = 1 to 2 I int a[8][4];
  • 214.
    Ques : Writea program to Print the transpose of the matrix entered by the user. -> create d AW the Already done 1 transpose store it Column Wise Prin ting in a new O I matrix O I 2 O 7 2 3 0 I Y -> I Y S 6 I 2 S 2x3 3 6 2 3x2
  • 215.
    2) Vector, 2D vector 2)DS A L Time & space complexity Sorting, searching DW I Linked list, stack, Quene, Trees, maps, Set, leaps Graphs, DP, OOPS skills Decode 2.0 Batch - C++, DSA (Paid) Mrvi, Sanket PWskills & College Wallah - Playlist eC++&DSA foundation course
  • 216.
    Strings 1D Array raghar II integer away char array (6): float, Char E','hav !
  • 217.
    What are strings andWhy are they used? -> Char Arrays L questions
  • 218.
    Declaration of Strings andtaking Input string str; ~ strings: "Raghav Garg", d ↓ string si getline/cin,s); cins; cout<<S;
  • 219.
    Indexing of characters in Strings strings: "abc"; dsitic strings: "raghar"; cont << S90]://v I length)). ASCII - O "o'-hull character cont<S; d
  • 220.
    Ques : Inputa string of length n and count all the vowels in the given string. ->
  • 221.
    Updation of a singlecharacter in string ↓ Done
  • 222.
    Ques : Inputa string of size n and Update all the even positions in the string to character ‘a’. Consider 0-based indexing. H.W. - ⑦@°=I> - - 012345678910 strings: "Raghav Garg"; E aaahavaGara
  • 223.
  • 224.
  • 225.
  • 226.
  • 227.
  • 228.
  • 229.
    Ques : Inputa string of even length and reverse the first half of the string. i I 012345 -> string s = "raghar"; - ↳ garhav
  • 230.
    Ques : Inputa string of length greater than 5 and reverse the substring from position 2 to 5 using inbuilt functions. Homework - - - strings: "raghar"; 012345 ↳ reverse (s. begin))+2, s. begin() + 1); 6
  • 231.
    to_string() -> intto string d int x = 12345; 4 strings: to-string(x);
  • 232.
    Ques : Returnthe total number of digits in a number without using any loop. Hint : Try using inbuilt to_string() function. x = 91632
  • 233.
  • 234.