Home > Back-end >  C language input a [10], an array with three functions to implement the following function respectiv
C language input a [10], an array with three functions to implement the following function respectiv

Time:02-24

Input a [10], an array with three functions, respectively, to realize the following functions:
(1) to calculate a sum of all the elements of an array and output;
(2) implement array b, its reverse save a, the array elements;
(3) a array arranged from big to small,

CodePudding user response:

Is the basis of written advice their implementation
1. To iterate through group accumulative
2 times a value in the array the array b, such as b [9 - I]=[I]
3. The bubble sort should learn, reference that would be great

CodePudding user response:

Int the sum (char * p, int num) {
Int sum=0;
for (int i=0; I & lt; Num. I++)
Sum=sum + p [I];
return sum;
}
Int reverse (char * a, char * b, int num) {
for (int i=0; I & lt; Num. I++) {
B=[I] a [num - I - 1);
}
return 0;
}
Int sort (char * p, int num) {
Int temp.
for(int i=0; Ifor(int j=0; JIf (p [j]

Temp=p [j];
P=p [j] [j + 1);
P=\ [j + 1);
}
return 0;
}

CodePudding user response:

Comprehensive above, the code for reference:
 # include & lt; stdio.h> 

10//# define N defining constants N=10

Void sum (int * p, int num)//calculate the sum of all the elements of an array and output
{
Int sum=0;
for (int i=0; I & lt; Num. I++)
Sum=sum + p [I];
Printf (" sum=% d \ n ", sum);
}

Int reverse (int * a, b, int * int num)//array b, reverse save a, the array elements;
{
for (int i=0; I & lt; Num. I++) {
B=[I] a [num - I - 1);
}
return 0;
}

Int the sort (int * p, int num)//array from big to small order
{
Int temp.
for(int i=0; Ifor(int j=0; JIf (p [j]

Temp=p [j];
P=p [j] [j + 1);
P=\ [j + 1);
}
return 0;
}

Int main ()
{
Int a [N], b [N].

for(int i=0; IA [I]=I + 1;
Printf (" % d ", a [I]);//1 2 3 4 5 6 7 8 9 10
}
printf("\n");

//1 calculate a the sum of all the elements of an array and output
The sum (a, N);

//2 array b, reverse save a, the array elements;
Reverse (a, b, N);
for(int i=0; IPrintf (" % d, b [I]);
}
printf("\n");

//3 a sort by from big to small array
Sort (a, N);
for(int i=0; IPrintf (" % d ", a [I]);
}
printf("\n");


return 0;
}

  • Related