Vous êtes sur la page 1sur 7

EXERCISE NO.

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:__________________

1. What is string value in C?


___________________________________________________________
2. Give the syntax of the following string functions: (string.h)
strcpy()
strcpy(string1, string2)
strncpy()
strcpy(string1, string2)
strcat()
strcat(string1, string2)
strcmp()
strcmp(string1, string2)
stricmp()
stricmp(string1,string2)
strncmp()
strncmp(const char *s1, const char *s2, size_t n
strnicmp
strnicmp(string1,string2,count
strlwr()
strlwr(string)
strupr()
strupr(string)
strnset()
strnset(string,c,count)
strset()
strnset(string,c,count)
strchr()
strchr(string, c)
strlen()
strlen(string)
strrev()
strrev(string)
strdup()
strdup(string)
3. Explain the following character functions: (ctype.h)
isalnum()
int isalnum(int ch);
isalpha()

int isalpha(int ch);

isdigit()

int isdigit(int ch);

islower()

int islower(int ch);

ispunct()

int ispunct(int ch);

isspace()

int isspace(int ch);

tolower()

int tolower(int ch);

toupper()

int toupper(int ch);

4. Give the
(math.h)
abs()
ceil()
fabs()
floor()
fmod()
pow()
pow10()
sqrt()

syntax

of

the

following

mathematical

functions:

int abs(int num);


double ceil(double num);
double fabs(double num);
double floor(double num);
double fmod(double x, double y);
double pow(double base, double exp);
double pow10(int n);
double sqrt(double num);

5. Explain the following conventional functions: (math.h)


atof()
double atof(const char *str);
atoi()
int atoi(const char *str);
atol()
int atol(const char *str);
itoa()
char *itoa(int num, char *str, int radix);
1. Evaluate the following expression using the following
char first[20], second[15];
char third[20] = God Loves U;
char fourth[20] = GOD BLESS U;
a.
b.
c.
d.
e.
f.
g.
h.
i.
j.

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

2. Answer TRUE if the expression will return non-zero and FALSE


if not. Evaluate using the following declarations:
char c = C, m = ?, i = t, b = 5;
a.
b.
c.
d.
e.
f.
g.
h.
i.
j.

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.

Evaluate the following expressions:


abs(5);
5
floor(5.5);
5
ceil(5);
5
fmod(pow(7,2)); _______________________________
sqrt(floor(25.12)); 5
fabs(pow(9,2)); _______________________________
atoi(451);
451
ceil(pow(5,3)); 125
fabs(-44.98);
_______________________________
ceil(fmod(5,1,5)); _____________________________

Vous aimerez peut-être aussi