Home > Back-end >  Insert a number error-detection orderly sequence
Insert a number error-detection orderly sequence

Time:01-30

Enter description:
The first line of input an integer (0 N 50 or less or less),
The second line enter an integer N ascending, input N integers separated by a space,
The third line input want to insert an integer,

Output description:
Output is a line, orderly arrangement of N + 1 integer,


 # include & lt; Stdio. H> 
Int main ()
{
Int N;
Int num [N].
int a;
Int I, m, n;
Int * ptr_n=& amp; N;
The scanf (" % d ", & amp; N);
for(i=0; I & lt; N; I++)
{
The scanf (" % d ", & amp; Num [I]);
}
The scanf (" % d ", & amp; a);
* ptr_n=N + 1;
for(i=0; I & lt; (N + 1); I++)
{
If (a & gt; Num [I] & amp; & A. & lt; Num [I + 1])
{
M=I + 1;
break;
}
}
For (I=(N + 1); I & gt; m; I -)
{
N=num [I];
Num=num [I] [I - 1);
Num=[I - 1] n.
}
Num [m]=a;
for(i=0; I & lt; (N + 1); I + +)
{
Printf (" % d \ t ", * (ptr_num + I));
}
return 0;
}



Thinking is confusion, help to see what are the problems
If there is no pointer and how to write?

CodePudding user response:

Enter the first, and then double circular bubble sort

CodePudding user response:

The compiler tell your problem, according to the first,

CodePudding user response:

Reference:
 # include & lt; Stdio. H> 

# define N 51

Int main ()
{
//int N;
Int num [N].
int a;
Int I, m, n, t;
//int * ptr_n=& amp; N;
The scanf (" % d ", & amp; N);
If (n<0 | | n> 50) n=50;

for(i=0; I & lt; n; I++)
{
The scanf (" % d ", & amp; Num [I]);
}
The scanf (" % d ", & amp; a);
//* ptr_n=n + 1;
for(i=0; I & lt; N; I++)
{
If (a & lt; Num [I])//& amp; & A. & lt; Num [I + 1])
{
M=I;//m=I + 1;
break;
}
}
If (I==n) m=n;
For (I=(n + 1); I & gt; m; I -)
{
T=num [I];
Num=num [I] [I - 1);
Num [I - 1]=t;
}
Num [m]=a;
for(i=0; I & lt; (n + 1); I + +)
{
Printf (" % 4 d, "num [I]);//printf (" % d \ t ", * (ptr_n + I));
}
system("pause");
return 0;
}

CodePudding user response:

The
reference 3 floor QZJHJXJ response:
for reference:
 # include & lt; Stdio. H> 

# define N 51

Int main ()
{
//int N;
Int num [N].
int a;
Int I, m, n, t;
//int * ptr_n=& amp; n;
The scanf (" % d ", & amp; N);
If (n<0 | | n> 50) n=50;

for(i=0; I & lt; n; I++)
{
The scanf (" % d ", & amp; Num [I]);
}
The scanf (" % d ", & amp; a);
//* ptr_n=n + 1;
for(i=0; I & lt; N; I++)
{
If (a & lt; Num [I])//& amp; & A. & lt; Num [I + 1])
{
M=I;//m=I + 1;
break;
}
}
If (I==n) m=n;
For (I=(n + 1); I & gt; m; I -)
{
T=num [I];
Num=num [I] [I - 1);
Num [I - 1]=t;
}
Num [m]=a;
for(i=0; I & lt; (n + 1); I + +)
{
Printf (" % 4 d, "num [I]);//printf (" % d \ t ", * (ptr_n + I));
}
system("pause");
return 0;
}


Your code is a little problem, the lack of a case, the last input is larger than the previous time, there will be a problem, don't seem to test

At the time of mobile location in the table below for the location of the n haven't fill data,


 # include & lt; Stdio. H> 

# define N 6

Int main ()
{
//int N;
Int num [N].
int a;
Int I, m, n, t;
//int * ptr_n=& amp; n;
The scanf (" % d ", & amp; N);
If (n<0 | | n>=N)
N=n - 1;

for(i=0; I & lt; n; I++)
{
The scanf (" % d ", & amp; Num [I]);
}
The scanf (" % d ", & amp; a);
//* ptr_n=n + 1;
for(i=0; I & lt; N; I++)
{
If (a & lt; Num [I])//& amp; & A. & lt; Num [I + 1])
{
M=I;//m=I + 1;
break;
}
}
If (I==n)
M=n;

//for (I=(n + 1); I & gt; m; I -)
For (I=n; I & gt; m; I -)
{
T=num [I];
Num=num [I] [I - 1);
Num [I - 1]=t;
}
Num [m]=a;
for(i=0; I & lt; (n + 1); I + +)
{
Printf (" % 4 d, "num [I]);//printf (" % d \ t ", * (ptr_n + I));
}
//system (" pause ");
return 0;
}


For your reference ~
  • Related