The following function is meant to return the maximum value
Solution
a)
float max(float vec[],int len)
{
//Declare the required variables.
int i;
float max=0;
for(i=0;i<len;i++)
{
if(vec[i]>max)
{
max=vec[i];
}
}
return max;
}
In the above program the local variable max1 should initialize to zero, otherwise it takes some garbage values. In that case you may not get exact output.
b)
The following function is find the absolute value for
the above function.
float max(float vec[],int len)
{
int i;
float max=-10,m=0;
for(i=0;i<len;i++)
{
if(vec[i]>max)
{
max=vec[i];
m=fabs(max);
}
}
return m;
}
The fabs() function is available in math.h header file,
So we include the header file in your program.
c)
int diagonalStripes(int A[],int len)
{
int i,j;
for(i=0;i<len;i++)
{
for(j=0;j<5;j++)
{
if(i==j)
{
A[i][j]=j;
}
}
}
for(i=0;i<len;i++)
{
for(j=0;j<5;j++)
{
printf(“%d”,A[i][j])
}
}
}
![The following function is meant to return the maximum value in vec, which contains len entries. float max(float vec[], int len) {int i; float max; for (i = 0; The following function is meant to return the maximum value in vec, which contains len entries. float max(float vec[], int len) {int i; float max; for (i = 0;](/WebImages/5/the-following-function-is-meant-to-return-the-maximum-value-985036-1761505976-0.webp)
![The following function is meant to return the maximum value in vec, which contains len entries. float max(float vec[], int len) {int i; float max; for (i = 0; The following function is meant to return the maximum value in vec, which contains len entries. float max(float vec[], int len) {int i; float max; for (i = 0;](/WebImages/5/the-following-function-is-meant-to-return-the-maximum-value-985036-1761505976-1.webp)