Professional Documents
Culture Documents
Cone Shot Part 5
Cone Shot Part 5
Part - 5
Functions
in One Shot
What and
Why? w
y
=
f(x)
n
y f(x)
3
I
= =
+
Repetition (to
8) avoids -
loops
2) Readable
External
↑ ·Good morning
function
How
you?
·
are
-
-
·
Good Morning
Khatam How
you?
-
· are
I
· Good Morning
2 call
How
· are
you?
R
&RY - do not
repeat yourself
Basic syntax
fun(){
// code
}
main() ->
starts from main()
return ;
↳ Khatam
How functions work : ek ke andar doosra,
doosre ke andar teesra
Kaam ki baate :
1) main() ek hi baar aata hai.
2) Starts with main
3) unlimited functions
Return type : Power function se samajte hai
sum of 2 numbers
*
tadd (inta, intb) <
return
-w
a b;
+ -N
3
return 7;
main()
E inta, bi
3
WoW
Library functions
rintf ("Hello");
&
scant("ood", (n);
sqrt (49);
pow(2, 3), ->23
Function Prototype - F
useless
Ques : Combination and Permutation
n = 7 #
urs
I
wc =
v= 3 31. 4!
1code
(n v)!
- =
(n v)x(n
- -
r -
1)
w
↓
number
Ques : Combination and Permutation
ncw =
nfact/rfact *uefact
Hact urt e
=
x
"
(+1
=
+2
u or
SAT 35
*
= =
=
Ques : Pascal triangle
A
O I
2 =
21
1- 1
-to
I
2 1-2- 1
3 3 2
3 1
K
- - -
6-4 1
Y 1-1 -
-
10 10 5 1
-1 -
3 -
- - -
15 20 15 6 I
6 1 6 -
- - - -
work:
*
"Pre function
"Pr:ch
Ques : Pascal triangle
j -
O U U
12345 + O 12345 +
O I 0 Co
'C,
&
I I I
L 1 To
I
2 12 1
2 "%,
3 7 33 1
33632, 3C "C
Y I 464( Y "C","Y,"Cy
S I
d
I - 10 10
S S
A A ↑
i i Cj
Ques : Pascal triangle OPTIMISED
Ultimate Method "Maths' -
ncr+=
-
(n + 1)!x(n
-
r
-
1)!
0
0Co
- "Co 'C, · 5 "Cr+ =
H-
rc=-a.*anrore
24.2C 22
3
33C, 3C, "C
=YCrtEnCLE
-
=
-
-
r -
=
=( (n r
l
-
-
Ques : Swap 2 numbers
inta 3;
=
intb 5;
=
V ↳W
a
b temp
int temp;
temp =
a;
a =b;
b =
temp;
Ques : Swap 2 numbers without
using a third variable
* W
s +58755
-
S
*
S
a b
a a
= +
bi
b a
=
-
b;
a a
=
-
b;
Scope of variable
C aukat
↳ limit
swapout
3
3inti, .
.
.
is
3
Formal parameters and Actual Parameters
void swap (inta, intb/<
int temp =
a;
a b,
=
b= temp;
return;
3
I
209 actual
swap (a,b); are
&
Pass by value & Pass by reference
void swap(inta, intbia
int
a b,
=
temp =
a;
got to
emp
b= temp;
return;
3
b
=
2;
9;
=
WE a
b
swap (a,b);
2
·
otes
*Pointers
↳ variable ka address stone
5;
W *
inta =
*
int x = ca
a
sh
*x 7; 3 x 20 U
6y522
=
Sx204
rintf("Oop",
& x); e
Printf(""op", (n); =
6y322
printf("Olod", *n); e5
*Pointers Swap 2 numbers
pass by reference
void swap (inta, intb/<
int temp =
a;
a b,
=
b= temp;
return;
3
I
209 actual
Swap (a, 2b) ;
are
2
of *5N
a
zoox
b
500x 000x stox
W
temp
900x
*No a w
x 300 x400 xs
*x + 25 [Pod]
*
y - x300[%p]
**
y
+ 25[Pod]
1) Gate Wallah -
(Programming
2) C++ ->
pointers
Homewor K
prime or not
Ques : Write a function to compute the greatest
common divisor of two given numbers
a, b GCDj HCF
↓
24 +
1, 2, 3, 4, 6, 8, 12, 24
for (inti =
1; i < min (a,b);i+ + k
3
State TRUE or FALSE :