Home > Back-end >  For help
For help

Time:05-03

Have no problem with dev - CPP, run the following program, but run on leecode error, please give directions!!!!!!!!!!!
Program content is to realize the palindrome judgment:

There's just one problem:
To store the input digital number on every one, I defined in the program with a capacity of 9999 array, how to implement according to the input number of digits to define an array of capacity??


#include
Int b [9999];
Int main ()
{
Int a, n=0, I=0, j=0, c;
Printf (" please enter a number \ n ");
The scanf (" % d ", & amp; A);
C=a;
For (a=c; A>=10; A=a/10)
{
[I] b=a % 10;
i=i+1;
}
[I] b=a % 10;
If (I % 2==1)
{
For (n=0; N<(I + 1)/2; N++)
{
If (b [n]==b [I - n])
{
J=j + 1;
}
}
If (j==(I + 1)/2)
Printf (" True ");
The else
Printf (" False ");

}
The else
{
For (n=0; N<=I/2; N++)
{
If (b [n]==b [I - n])
{
J=j + 1;
}
}
If (j==I/2 + 1)
Printf (" True ");
The else
Printf (" False ");
}
}

This is an error!!!!!!!!!!!!!!!


Line 47: Char 5: error: redefinition of "main" [c] solution.
Int main (int arg c, char * argv []) {
^ ~ ~ ~

CodePudding user response:

The building Lord - this code will be a problem, see comments, for reference:
//program content is to realize the palindrome judgment: 

//there's just one problem:
//in order to store the input digital number on every one, I defined in the program with a capacity of 9999 array, how to implement according to the input digital
//digits to define an array of capacity??


#include

Int main ()
{//problem a:
Int b [10].//C int scope is: in 2147483648 ~ 2147483647, the largest decimal is 10 digits, so b [?] Not so much

Int a, n=0, I=0, j=0, c;
Printf (" please enter a number \ n ");
The scanf (" % d ", & amp; A);
C=a;
//if here to join the definition of dynamic array, the foremost int b [10]; Definition to delete or add '//' instead of the head annotation
//based on the input number of digits to define an array capacity: first you need to calculate the input number of digits of n,
//then: int * b=(int *) malloc (sizeof (int) * n); Memset (b, 0, sizeof (int) * n);

For (a=c; A>=10; A=a/10)
{
[I] b=a % 10;
i=i+1;
}
[I] b=a % 10;
If (I % 2==1)
{
For (n=0; N<(I + 1)/2; N++)
{
If (b [n]==b [I - n])
{
J=j + 1;
}
}
If (j==(I + 1)/2)
Printf (" True ");
The else
Printf (" False ");
}
The else
{
For (n=0; N<=I/2; N++)
{
If (b [n]==b [I - n])
{
J=j + 1;
}
}
If (j==I/2 + 1)
Printf (" True ");
The else
Printf (" False ");
}
//if you define [b] is dynamic, and at the end of the code statement before input: free (b); Explicitly release the array, or without=implicit release,

return 0;
}


//the problem 2:
//error: a redefinition of 'main' compiler error, repeat the definition of the main
//this question bank operation method is: you just need to make up for all the lack of code

CodePudding user response:

To return an int int main?
  • Related