Académique Documents
Professionnel Documents
Culture Documents
7
NAME: Luzvi Dabuet
YR. & SEC. PBDIT
DATE:___________________
SCORE:__________________
A.
1. What is a function? What is the syntax of a function?
- A function is a statement that performs a specific
repetitive task.
- Return_type function_name (parameter1,.parameterx)
{
Variable_declaration
}
2. What is the use of the data type void?
- Void is no value. Void is useful because there are specific
task that doesnt require any output or return values
3. Explain a function that is called by value?
- Value is used locally in place of the corresponding
parameter
4. What is an address? A pointer? Explain a function that is
called by reference?
- Address is a physical allocation of a variable. Pointers are
designed for storing memory address.
5. Explain a function that returns a value?
- Expression if a function contains a return statement then
the value or expression is passed back to the callin
environment
B. TRACING
1. Trace the following programs:
(a)
void trace1(int x, int *y)
{
X = 5; *y =2;
printf(%2d %2d\n, x, *y);
}
main( )
{
int x, y;
clrscr( );
x = y = 3;
trace1(x, &y);
printf(%2d %2d\n, x, y);
getch( );
return 0;
}
Answer a:
5
3
2
2
(b)
void trace(int x, int *y, int z)
{
x = 1; *y=2;z=4;
printf("%2d %2d %2d\n",x, *y, z);
}
main()
{
int x=1, y=3,z=4;
clrscr();
printf("%2d %2d %2d\n",x,y,z);
trace(y,&x,z);
printf("%2d %2d %2d\n",x,y,z);
trace(x,&z,y);
printf("%2d %2d %2d\n",x,y,z);
trace(z,&y,x);
printf("%2d %2d %2d\n",x,y,z);
getch();
return 0;
}
Answer b:
1
1
2
1
2
1
2
3
2
3
2
3
2
2
4
4
4
4
2
4
2
(c)
#include<stdio.h>
#include<conio.h>
void kar1(char *c, char b, char *a)
{
*a = 'c'; b = 'a'; *c = 'b';
printf("%c %c %c\n", *a, b, *c);
}
void kar2(char *b, char *a, char *c)
{
*a = 'b'; *b='c'; *c ='a';
printf("%c %c %c\n", *a, *b, *c);
}
main()
{
char a = 'a', b = 'b', c =
clrscr();
printf("%c %c %c\n", a, b,
kar1(&a,b,&c);
printf("%c %c %c\n", a, b,
kar2(&a,&b,&c);
printf("%c %c %c\n", a, b,
kar1(&c,b,&a);
printf("%c %c %c\n", a, b,
kar2(&c,&a,&b);
printf("%c %c %c\n", a, b,
getch();
return 0;
}
'c';
c);
c);
c);
c);
c);
Answer c:
a
c
b
c
c
c
c
b
b
b
a
a
b
b
a
b
c
a
c
b
c
a
a
b
b
a
c
(d)
#include<stdio.h>
#include<conio.h>
void kar1(char *a, char *b, char *c)
{
*a = 'c'; *b='a'; *c ='b';
printf("%c %c %c\n", *a, *b, *c);
}
main()
{
char a = 'c', b = 'b', c = 'a';
clrscr();
printf("%c %c %c\n", a, b, c);
kar1(&a,&b,&c);
printf("%c %c %c\n", a, b, c);
kar1(&c,&b,&a);
printf("%c %c %c\n", a, b, c);
kar1(&b,&a,&c);
printf("%c %c %c\n", a, b, c);
getch();
return 0;
}
Answer d:
c
c
c
c
b
C
b
b
a
a
a
a
a
c
A
b
B
b
C
b
a
EXERCISE NO.8
NAME:Luzvi Dabuet
YR. & SEC.PBDIT
DATE:___________________
SCORE:__________________
isdigit()
islower()
ispunct()
isspace()
tolower()
toupper()
4. Give the
(math.h)
abs()
ceil()
fabs()
floor()
fmod()
pow()
pow10()
sqrt()
syntax
of
the
following
mathematical
functions:
strrev(fourth);
strupr(third);
strncat(fourth,third,5);
strlwr(fourth);
strncpy(first,fourth,5);
strcpy(second,third);
strlen(third);
strncat(third,fourth,4);
strlen(third);
strncpy(first,third,3);
U SSELB DOG
GOD LOVES U
GODBLESS UGod B
god bless u
GOD B
God Loves U
11
God Loves UGOD
11
God
isdigit(b);
isalpha(c);
isspacee(m);
isupper(c);
isalnum(b);
ispunct(m);
islower(i);
isupper(c);
isalnum(b);
islower(i);
True
True
False
True
True
True
True
True
True
True
3.
a.
b.
c.
d.
e.
f.
g.
h.
i.
j.