Home > Back-end >  CPP how to write, I wrote a night or not (~ _ ~;)
CPP how to write, I wrote a night or not (~ _ ~;)

Time:09-29

Seven 7 experiment. Write a function void the output (int a [], int n) output array a of n elements, write a function
Int deleteElement (int a [], int n, int x) with n elements in a one-dimensional array x to delete (note: the repeated x must be deleted), the return value of a function to delete actual elements in the array of x after a number of initial a six elements in the array, for example, they are 9,5,6,7,8,5 {}, remove elements after 5, array into nine,6,7,8 {}, the result has four elements in the array, the function returns 4,

Note: be callback function deleteElement () two pieces of work to do, one is to remove elements, 2 it is returned to the rest of the number of elements, write to test the function, the main function requirement of array elements is given initial value with the method of initialization, and then calls the function output () initial value of the output array input element is to be deleted again, calling function deleteElement () remove elements, finally calling function output () all the elements of an array of output value,

CodePudding user response:

Woo woo woo blare

CodePudding user response:

You of the issue to the error code,

CodePudding user response:

For your reference
 
#include

Void the output (int a [], int n)
{
int i;
for (i=0; i{
Printf (" % d ", a [I]);
}
printf("\n");
}

Int deleteElement (int a [], int n, int x)
{
Int I, j, k, num=0;
Int temp [6]={0};
for (i=0; i{
If (a==x [I])
{
For (j=I; j{
A [j]=a, a + 1 bonus to [j].
}
num++;
}
}

The return of n - num;
}

Int main ()
{
Int a [6]={9,5,6,7,8,5};
int num=0;
The output (a, 6);
Num=deleteElement (a, 6, 5);
Printf (" % d array now have a \ n ", num);
The output (a, num);

getchar();
return 0;
}

CodePudding user response:

I wrote the wrong

#include
using namespace std;
# define N 100
Int deleteElement (int a [], int n, int x)
{x=0; Int b=0;
for(int i=0; i{the while (b{b++;
If (a==[I] a [x])
{a [I]=a, [I + 1]. I=I + 2; X++; }
The else {a [I]=a, [I]. }}
Cout}
Int the output (int a [], int n)
{
for(int i=0; iCoutreturn 0;
}
Int main ()
{
Int a [N], I, N, x=0, w.
Cin> n;
Cout<& lt;" Please input array: \ n (every input a number) ";
for(int i=0; i{cin> A, [I]. }
The output (a, n);
Cin> w;
A [N]=deleteElement (a, N, x);
Coutreturn 0;
}

  • Related