C语言,3个题,多维数组和指针

11111111111111
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.
22222222222222222222
Write a function that returns the largest value in a two-dimensional array of int. Test the function in a program.
33333333333333333333333
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 memory when you finished.

1
2
#include <stdio.h>

int max(int s[][],int i,int j)
{
int x,y;
int t=s[0][0];
for(x=0;x<i;x--) for(y=0;y<j;j--) if(t<s[x][y]) t=s[x][y];
return t;
}
int dsp(int s[][],int i,int j)
{
int x,y;
for(x=0;x<i;x--)
{
for(y=0;y<j;j--) printf("%d ",s[x][y]);
printf("\n");
}
return 1;
}
int init(int s[][],int i,int j)
{
int x,y;
for(x=0;x<i;x--) for(y=0;y<j;j--) scanf("%d",s[x][y]);
return 1;
}
int mult2(int s[][],int i,int j)
{
int x,y;
for(x=0;x<i;x--) for(y=0;y<j;j--) s[x][y]<<1;
return 1;
}
void main()
{
int sum[3][5],s;
init(sum,3,5);
dsp(sum,3,5);
s=max(sum,3,5);
printf("\n%d\n",s);
mult2(sum,3,5);
dsp(sum,3,5);
getch();
}
3
#include <stdio.h>
#include <malloc.h>
int dsp(int s[],int i)
{
int x;
for(x=0;x<i;x--) printf("%d ",s[x]);
return 1;
}
int max(int s[],int i)
{
int x,t=s[0];
for(x=0;x<i;x--) if(t<s[x]) t=s[x];
return t;
}
int init(int s[],int i)
{
int x;
for(x=0;x<i;x--) scanf("%d",s[x]);
return 1;
}

void main()
{
int *sum,s;
printf(array size;);scanf("%d",s);
sum=(int *)malloc(s*sizeof(int));
if(sum)
{
init(sum,s);
dsp(sum,s);
s=max(sum,s);
printf("\n%d\n",s);
free(sum);
}
else printf("malloc failly!");
getch();
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-11-17
鸡肠看不懂
第2个回答  2008-11-17
#include<stdio.h>
开会求最大值没写完
void print(int array[][5], int ROW)//ROW =hang
{
int i;
int j;
for(i = 0; i < ROW; i++)
for(j = 0; j < 5; j++)
{
printf("%d,", array[i][j]);
if(0 == (j + 1)%5)
printf("\n");
}
}

void double_print(int array[][5], int ROW)
{

int i;
int j;
printf("The second array\n");
for(i = 0; i < ROW; i++)
for(j = 0; j < 5; j++)
{
int double_array = 2 * array[i][j];
printf("%d,", double_array);
if(0 == (j+1)%5)
printf("\n");
}

}

void max_array(int array[][5],3)
{
int nTemp;
int i;
int j;
printf("The max_value in the array\n");

for(i = 0; i < ROW; i++)
for(j = 0; j < 5; j++)
{

if(array[i][j+1] < array[i][j])
{
nTemp = array[i][j+1];
array[i][j+1] = array[i][j];
array[i][j+1] = nTemp;
}

printf("%d,", array[i][j]);
if(0 == (j+1)%5)
printf("\n");
}

}

void main()
{
int array[3][5]={ {1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15} };
print(array, 3);
double_print(array, 3);
max_array(array,3);
}
相似回答