Home > Back-end >  C language programming questions
C language programming questions

Time:09-22

Introduction to just learn c, what all don't understand, if the problem is too stupid, we don't recommend
I wrote an input a string of Numbers, sorted output code, compile successfully but I use digital tried but couldn't get the correct result, don't know where in addition to the problem, the other for loop array assignment when don't know how the keyboard to operate, was Spaces and the carriage return need

#include

Int main ()

{

Int j, I, j;

The scanf (" % d ", & amp; M);

Int a, [m].



for(i=0; i
{

The scanf (" % d ", & amp; A [I]);

}



For (j=m - 1; J> 0; J -);

{

If (a [j] <- 1 a [j])

{

Int temp=a, [j].

A [j]=a, [1].

- 1 a [j]=temp;

}

}

for(j=0; j
Printf (" % d ", a [j]);



return 0;

}


CodePudding user response:

The
refer to the original poster hsyihsy response:
introduction to just learn c, what all don't understand, if the problem is too stupid, we don't recommend
I wrote an input a string of Numbers, sorted output code, compile successfully but I use digital tried but couldn't get the correct result, don't know where in addition to the problem, the other for loop array assignment when don't know how the keyboard to operate, was Spaces and the carriage return need

#include

Int main ()

{

Int j, I, j;

The scanf (" % d ", & amp; M);

Int a, [m].



for(i=0; i
{

The scanf (" % d ", & amp; A [I]);

}



For (j=m - 1; J> 0; J -);

{

If (a [j] <- 1 a [j])

{

Int temp=a, [j].

A [j]=a, [1].

- 1 a [j]=temp;

}

}

for(j=0; j
Printf (" % d ", a [j]);



return 0;

}



With two loops, can fill a single debugged should be able to find problem

CodePudding user response:

Program has two the scanf, should add a read between the return operation,
For example: getchar ()
Or:
 char c; 
The scanf (" % c ", & amp; C);

CodePudding user response:

 # include & lt; Stdio. H> 
Int main ()
{
Int j, I, j;

The scanf (" % d ", & amp; M);

Int * a=new int [m].//-- -- -- -- -- -- -- to use dynamic allocation space -- -- -- -- -- -- -- -- -- -- --



for (i=0; i
{

The scanf (" % d ", & amp; A [I]);

}

for (i=0; i {

For (j=0; J & lt; 1 - I; m - + + j)//-- -- -- -- -- -- -- -- -- -- -- -- circulation changes -- -- -- -- -- -- -- --

{

If (a [j]
{

Int temp=a, [j].

A [j]=a, a + 1 bonus to [j].

A=\ [j + 1];

}

}
}
for (j=0; j
Printf (" % d ", a [j]);

The delete [] a;//-- -- -- -- -- -- -- -- -- -- -- -- free memory -- -- -- -- -- -- -- -- -- -- -- -- -- --
return 0;
}


VS2015 c + + environment

CodePudding user response:

For you mentioned
"For loop array assignment when don't know how the keyboard to operate, is space and carriage returns need?"
The problem, in fact, space and carriage returns can be


For the scanf () method of use, please refer to "the scanf () function usage"
Wish I could help you!

CodePudding user response:

Thank you for your patience to answer!

CodePudding user response:

reference 4 floor MianHou response:

for you mentioned"For loop array assignment when don't know how the keyboard to operate, is space and carriage returns need?"
The problem, in fact, space and carriage returns can be


For the scanf () method of use, please refer to "the scanf () function usage"
Wish I could help you!

Thank you for your patience to answer!

CodePudding user response:

The scanf (" % d ", & amp; M);

Int a, [m].

The C language definition does not support this array,
Int * a=new int [m]. This is a c + + written, c use malloc
  • Related