Home > Back-end >  A small program, run out, ask for advice
A small program, run out, ask for advice

Time:11-19

Title: an integer input, enter the digits and cycle show 1234567890, the same integer value

#include
Int main (void)
{
int n;
int i,j;
int a;
Printf (" please enter an integer: ");
The scanf (" % d ", n);
I=n/10;
for(j=0; j<=I; J++) {

Puts (" 1234567890 ");
}

A=n % 10;
{switch (a)
Case 1: printf (" 1 "); break;
Case 2: printf (" 2 "); break;
Case 3: printf (" 3 "); break;
Case 4: printf (" 4 "); break;
Case 5: printf (" 5 "); break;
Case 6: printf (" 6 "); break;
Case 7: printf (" 7 "); break;
Case 8: printf (" 8 "); break;
Case 9: printf (" 9 "); break;
Default: puts (" 0 "); break; }
return 0;
}

CodePudding user response:

With the switch selection structure is not very appropriate, such as 15, the original program can output
1234567890
5
Rather than
1234567890
12345

 # include & lt; Stdio. H> 
#include

Int main (void)
{
int n;
int i,j;
int a;
Printf (" please enter an integer: ");
//the scanf (" % d ", n);
The scanf (" % d ", & amp; N);
I=n/10;
//for (j=0; j<=I; J++)
for(j=0; j{
Puts (" 1234567890 ");
}

A=n % 10;
/* the switch (a)
{
Case 1:
Printf (" 1 ");
break;
Case 2:
Printf (" 2 ");
break;
Case 3:
Printf (" 3 ");
break;
Case 4:
Printf (" 4 ");
break;
Case 5:
Printf (" 5 ");
break;
Case 6:
Printf (" 6 ");
break;
Case 7:
Printf (" 7 ");
break;
Case 8:
Printf (" 8 ");
break;
Case 9:
Printf (" 9 ");
break;
Default:
Puts (" 0 ");
break;
}
*/
For (j=1; J & lt;=a; J++)
{
Printf (" % d ", j);
}
return 0;
}


Can also change an idea:
 int main (void) 
{
Int I, j, n.
j=1;
Printf (" please enter an integer: ");
The scanf (" % d ", & amp; N);
for(i=0; IPrintf (" % d ", j);
j++;
If (j==10)
J -=10;
}
printf("\n");
return 0;
}

CodePudding user response:

This should be the scanf (" % d ", & amp; N);

CodePudding user response:

refer to the second floor wxf54318 response:
this should be the scanf (" % d ", & amp; N);

Thank you, I went back to try, I actually didn't find this little mistake

CodePudding user response:

reference 1/dogear:) response:
with the switch selection structure is not very appropriate, such as 15, the original program can output
1234567890
5
Rather than
1234567890
12345

 # include & lt; Stdio. H> 
#include

Int main (void)
{
int n;
int i,j;
int a;
Printf (" please enter an integer: ");
//the scanf (" % d ", n);
The scanf (" % d ", & amp; N);
I=n/10;
//for (j=0; j<=I; J++)
for(j=0; j{
Puts (" 1234567890 ");
}

A=n % 10;
/* the switch (a)
{
Case 1:
Printf (" 1 ");
break;
Case 2:
Printf (" 2 ");
break;
Case 3:
Printf (" 3 ");
break;
Case 4:
Printf (" 4 ");
break;
Case 5:
Printf (" 5 ");
break;
Case 6:
Printf (" 6 ");
break;
Case 7:
Printf (" 7 ");
break;
Case 8:
Printf (" 8 ");
break;
Case 9:
Printf (" 9 ");
break;
Default:
Puts (" 0 ");
break;
}
*/
For (j=1; J & lt;=a; J++)
{
Printf (" % d ", j);
}
return 0;
}


Can also change an idea:
 int main (void) 
{
Int I, j, n.
j=1;
Printf (" please enter an integer: ");
The scanf (" % d ", & amp; N);
for(i=0; IPrintf (" % d ", j);
j++;
If (j==10)
J -=10;
}
printf("\n");
return 0;
}

Thank you, after hearing what you said the switch feels as though it is not quite right

CodePudding user response:

reference 1/dogear:) response:
with the switch selection structure is not very appropriate, such as 15, the original program can output
1234567890
5
Rather than
1234567890
12345

 # include & lt; Stdio. H> 
#include

Int main (void)
{
int n;
int i,j;
int a;
Printf (" please enter an integer: ");
//the scanf (" % d ", n);
The scanf (" % d ", & amp; N);
I=n/10;
//for (j=0; j<=I; J++)
for(j=0; j{
Puts (" 1234567890 ");
}

A=n % 10;
/* the switch (a)
{
Case 1:
Printf (" 1 ");
break;
Case 2:
Printf (" 2 ");
break;
Case 3:
Printf (" 3 ");
break;
Case 4:
Printf (" 4 ");
break;
Case 5:
Printf (" 5 ");
break;
Case 6:
Printf (" 6 ");
break;
Case 7:
Printf (" 7 ");
break;
Case 8:
Printf (" 8 ");
break;
Case 9:
Printf (" 9 ");
break;
Default:
Puts (" 0 ");
break;
}
*/
For (j=1; J & lt;=a; J++)
{
Printf (" % d ", j);
}
return 0;
}


Can also change an idea:
 int main (void) 
{
Int I, j, n.
j=1;
Printf (" please enter an integer: ");
The scanf (" % d ", & amp; N);
for(i=0; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related