C语言达人帮忙做下简单的作业。会的联系我QQ178930589 悬赏

来源:百度知道 编辑:UC知道 时间:2024/05/27 16:11:20
1.Write a program that declares a 3 by 5 two-dimensional array and initialises it with some values of your choice. The program should:
a. print all the values,
b. double the values
c. print again all the values
Write a function that is responsible for displaying the values and a second function that doubles the values. The functions could take as arguments the array name and the number of rows as arguments.

2.Write a function that returns the largest value in a two-dimensional array of int. Test the function in a program.

3.Write a function that returns the largest value in a one-dimensional array of int. Test the function in a program. Allow the user to specify the size of the array at execution time. Allow the user to provide the array values during execution. Use malloc() to allocate space for the array. Use the resulting pointer to call the function that is responsible for processing the array elements. Print the largest value. Free the mem

#include <malloc.h>
#include <stdio.h>

int *maxVal(int *array, int len)
{
int *res = array;
for (int i=0; i<len; i++)
{
if (*res<*array)
{
res = array;
}
array++;
}
array = res;
return array;
}

void main()
{
int *array = NULL;
int length = 0;
printf("input length of array: ");
scanf("%d", &length);
getchar();
array = (int*)malloc(sizeof(int) * length);
printf("input all members\n");
for (int i=0; i<length; i++)
{
scanf("%d", array+i);
}

int *head = array;
printf("%d\n", *maxVal(array, length));
array = NULL;
free(head);

}

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define ROW 5
#define COL 5

int maxEle(int a[ROW][C