C Ob From Functions
C Ob From Functions
Aim
To i t e a C proqroam to find the facoriod
Algorthm
Stpl START
Step 2 READ n
Step3 i fact 1
Stp4: FoR t : n
fact fat *i
Ct+
END FobR
PPINT fact
Steps
Step 6
Construck p m y declaning funchons
agument
th
* t h rebun tyPe
A h agumens
* t t h o u t xturn type
Step 7 : STDP
Program
Aith eturn bype, kAth ag umunt
K3tdio As
#in clude
t fact ( int) i
void matn C)
# Lhclude Cstdio.h)
roid fact Cint);
votd mat'n l)
number: ");
pintf ("Enter
a
fact Cn)
void fa ct ( t n)
t tact 1
ck:n t+)
forCc1
fact fact *;
t fact c);
void main()
int tn fact I
incude <s+dio.As
void fact C);
votd m ain C)
fact C),
3
void fact C)
int t, n, fact : I
Prtf C"Enter a number: ");
sCanfl "7J, *n)
for Ctl, ie en Ctt)
fact facf *i
3
prntf C"Factonial td " fa ct);
etun 0
Pesult
These þrogramd ae exe cuted and heir
ousputs a erhed
Outpuk
Enter a numbe7: 5
Factoriol u 120
2.
Check Palin drome or not
Aim.
TD Condtutt a c prog ram to check huthar the
Agorthmn
Step START
Step 2 NITIALISE void palin d>om ( har sti])
Step 3 NITIALI SE Char str Lsv]
Slep 14 : STDP
Pro m
#include (stdlo.As
## include String A>
char str[o];
printA ("nPleaseenkr Atrng: "7;
jets (str)
palind ome (shr);
return 0
i int t, en
iht flag-0;
lenA+rlen(str)
for Cto te len ; itt
f (str[i] != str [n i ] )
fl4
brea k
3
If Cflega o)
pintf ('In s u apalind vom stning dtr);
che
printtl"\ns not a palindrome stm'ng str);
venAed
Output
Please enter
stnna: abba
abba a
bau'nd rome lmng
3. oPy a string tthout strPy C)
Alm
Td Corstuct a c
program to Copy a
string
Ltthous strpy(
Algonthm
Sep1 START
Sep 2 DECLARE zstrcpy (char al[1, chara2[])
&tep3 n main
function
INITIALIsE al[203, a2 [zo
Step4 READ a1
Step S CALL 2strpy (a1, a2)
Sep 6 : PRINT a , a z
Pogram:
c l u d e <stdio.As
void xstrcP y ( char al L], char a2[ 1);
ht main C)
descending
0rdr usins funchons
ascn ding o>
Algorthm
pecursive unchons
Factoral of a number
Aim
TD bo factonal
Construct a C poqram fnd the
Algonthm:
Stp START
0r equal to zeo.
ram:
#uncludi Cstdio.AS
og t fact (long int);
nt man C)
De bn
number:7
printf ("Enter o
scant ("/1d , *n)
printf 'TK factorias KAd in Kld) n, fac# Cn)) ;
Aetun o
3
int n)
ht fact (long
i (ni?
Atturn n *foct (n-i7;
eue
turn I
3
Result Th proram
euha
and the ouhput
venAed.
Output:
a
numbe: 5
Ener
120
The factonal of
5
Jum ofh natual numbers.
Aim
D Constuct a
cproram find the s m of
n natura numbu us ing retursion .
Algorithm:
Step: START
Skep 2: READ a poSiive number
Program
#ucud Cstdi'o. As
it Sum(int);
bt matn C )
int n
printf (" Enter ranz: ");
sCantC"7d , in) ;
rinlf C TRe sum of td numbers i dyn,SumCni);
Auturn O
3
i t &umCiht n)
ItCn! o)
t u r n n+ Sum(n-1)
che
xturn n
3
RAsut Th prog
pro5** ram
czucukd and the output
Asvenihed
Output:
Enter range: lo
Th Sum
of 1o numbers s S
valut of m
Fiding
musin9 recui'on .
Algonthm:
Step!: START
Stp 7 &TOP
Pogram
#in cude (st dio. A
t powey (ints int )
t manC)
int m,n
ninit ("Enter base number: "7;
stnf (" ",km),
prtniF ("Enter ezponent: ")
sCanf("A")an);
printf C Ta valu of d^ya in td ,m,n, poner (min);
Aeturn o
elue
veun I
3
Venhed
Octput
number : 2
base
Ener
Enter exponent: lo
lo s lo24
lue of 2
TRe