Assignment 4
Assignment 4
Assignment #4,
1. Explain what is likely to happen when the following situations are encountered in
a program.
• Data type of one of the actual arguments (calling function) does not match
with the type of the formal argument (function prototype and definition).
• The type of expression used in return statement does not match with the type
of the function.
2. Write a function that can be called to compute the product of the two matrices of
size m by n and n by m. The main function provides the values for m and n for
two matrices.
3. Using this code what can you say about the f() near the origin? What happen if we
remove + sign from printf command
# include <stdio.h>
# include <math.h>
double f(double);
void main()
{
double x;
for(x=-.25;x≤.25;x=x+.01)
printf(“f(%+.2f)=%.13f\ n”,x,f(x));
}
double f(double x)
{
return (tan(sin(x))-sin(tan(x)));
}
4. Write a function exchange() to interchange the values of two variables (x&y) and
then call this in main(). Assume that x and y are global variables.
# include <stdio.h>
int a = 1, b = 2, c = 3;
int f(void);
int main()
{
printf(“%d\n”,f());
printf(“%d%d%d\n”,a, b, c);
return 0;
}
int f(void)
1
{
int b, c;
a = b = c = 4;
return (a + b + c);
}
what will happen if you will replace declaration statement int a = 1, b = 2, c = 3
by extern int a = 1, b = 2, c = 3.
(a). to make a function user strlen() to determine the exact length of string (mes-
sage) and then match your result with strlen() function (define in string.h).
(b). to copy the message to text 1 using the loop.
(c). to copy the message to text 2 using pointer arithmetic (ta points to message
and tb points to text 2).