0% found this document useful (0 votes)
17 views11 pages

Functions 2

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)
17 views11 pages

Functions 2

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/ 11

Today'sagenda

factorial
ne Py
4 functions
a factorial
Given Point factorial
a
of N
Quiz 1
factH 1 2 3 4 24

a 1 2 3 4 to a
fact
11psweds Code
Public Static void main C L

int n Son nentInte

int ans 1
int i t ie itt h
for i
n

ans i ans

3
System out pointer ans
re 4
int ans 1
i ien
ans sans i

I
2 t
3 3 4t
system out pointer ans
s
henit
11 C and Po
ng a
Quiz 2 5C 0
y ELI
10

Quiz 3 P t P Ig
Go

a Given n and s write an algorithm to calculate hey

É
I PSuedo Code

P S v main C 4
Scanner Sen new Scanner system.in
int n Son next Inte
int r Sch neat Intl

int
fact
n I
int i is n it I
for Ig
n
fact nfactti

int act 1
ofinti I is o itt
for i
fact o
fact
3

lint i t i cen itt h


for
o

mo
fact nm
fact is
g
int ans
fact fact
n nm
fact
System out Pointer ans
DRY Do not repeat yourself
to
function

Screw drives open 2 close nut bolt

I
buy screwdriver

Open close table's nut bolt use the


previously
boughtscrew
driver
out

Syntax outputtype name


Skeffington function

Public stay name input

I statement I
11 Statement 2

I
Public Static void mainC L
scannerson new Scannersystem.in scannerSen new Scannersystem.in
int n son neatIntel int n son neatIntel
fact n
for inti icon itt h intr f
public static int
ans i ans i fact
for inti ie n itt h
3 ans i ans i
mmmm
s return ans
z

Call Stock
Public Static void mainC L
scannerson new Scannersystem.in
int n son neatIntel

g systemout pointIn at
su 4

fft
mii
ÉÉ
if g
detumans main
ÉÉ
24

return in Balak in loop


function for

Called funct C but you don't want to setum


anything from there type of function should
be void
Break till 9823 Pra
I co using function

Public Static void main C L


Scanner Sen Scanner system.in
new

int n Son next Inte


int o Son next Intel

int n
fact fact
n

int a Co
fact fact
int hmm
fact fact n o

int ans
fact Efact
n
nonofact
System out pointer ans

public static int intr


fact
postings icon itt h
ans i ans i

return ans
3
Public Static void mainC L
scanner son new Scannersystem.in
I
int n son nextIntel
int o son nextIntel

int nfact fact n ÉÉ


É

of
int ans i nfact act
systemoutpointerans
nmofact

j
viiians ans imin so

many gigs
3

no 53 2

main C7 I
error

intgns s.gg 333


No
int T
Public Static void sum int a int b int c I

return at btc
Quiz 4
Public Static void main stringC args
packet
fits
Public Static int Product
I return atab
int a int b I
if y
15

no output

Quiz g

Public Static void main stringC args f


int ans Subtract 5,10
systemoutpointer ans
3 error

Public Static void subtract int a int b I


return a b

3
Quiz 68

Public Static void main


stringC args f
int na cube37

system out points add 4 4 0

PublicStatic int add


return at bg
35

int a int b 1 jÉ y 1

Public Static int cube int a L


cubfaism
return at a tea ni 27

You might also like