Home > Back-end >  Rookie self-study c primer, a great god solve puzzles
Rookie self-study c primer, a great god solve puzzles

Time:10-20

Why turned negative input after 11, already defined num for long ah, ask good intention person to help me this dish chicken

CodePudding user response:

Long int the maximum is 2147483647

CodePudding user response:

The
reference 1 floor? Victor.?? Response:
long int the maximum is 2147483647

Why always output after I use the long long 12 digits, and each number only and is not correct

CodePudding user response:

refer to the second floor m0_46379100 response:
Quote: refer to 1st floor? Victor.?? Response:
long int the maximum is 2147483647

Why always output after I use the long long 12 digits, and you only and don't correct

You put the source code, I give it a try

CodePudding user response:

The
reference 3 floor? Victor.?? Response:
Quote: refer to the second floor m0_46379100 response:

The
Quote: 1 reference building? Victor.?? Response:
long int the maximum is 2147483647

Why always output after I use the long long 12 digits, and you only and don't correct

You put the source code, I try

#include
#include
#include
Int main ()
{
Int sum=0, count=0;
Long long num.
Printf (" please enter a number: ");
The scanf (" % l64d ", & amp; Num);
Do {
If (num<0)
{
Printf (" please enter a number greater than 0: ");
The scanf (" % l64d ", & amp; Num);
}
} while (num<0);


While (num!=0)
{
The sum +=num % 10;
Num/=10;
count++;
}
Printf (" digit % d, the sum of the number of you is % d, \ n ", count, sum);
}

CodePudding user response:

Try this
 # include & lt; stdio.h> 
Int main ()
{
Int sum=0;
int count=0;
Long long int num.
Printf (" please enter a number: ");
The scanf (" % LLD, & amp; Num);
Do {
If (num<0)
{
Printf (" please enter a number greater than 0: ");
The scanf (" % LLD, & amp; Num);
}
} while (num<0);


While (num!=0)
{
The sum +=num % 10;
Num/=10;
count++;
}
Printf (" digit % d, the sum of the number of you is % d, \ n ", count, sum);
}

What is % l64d operation

CodePudding user response:

The
reference 5 floor? Victor.?? Response:
try this
 # include & lt; stdio.h> 
Int main ()
{
Int sum=0;
int count=0;
Long long int num.
Printf (" please enter a number: ");
The scanf (" % LLD, & amp; Num);
Do {
If (num<0)
{
Printf (" please enter a number greater than 0: ");
The scanf (" % LLD, & amp; Num);
}
} while (num<0);


While (num!=0)
{
The sum +=num % 10;
Num/=10;
count++;
}
Printf (" digit % d, the sum of the number of you is % d, \ n ", count, sum);
}

What is % l64d operation

Ok thank you very much

CodePudding user response:

The
reference 5 floor? Victor.?? Response:
try this
 # include & lt; stdio.h> 
Int main ()
{
Int sum=0;
int count=0;
Long long int num.
Printf (" please enter a number: ");
The scanf (" % LLD, & amp; Num);
Do {
If (num<0)
{
Printf (" please enter a number greater than 0: ");
The scanf (" % LLD, & amp; Num);
}
} while (num<0);


While (num!=0)
{
The sum +=num % 10;
Num/=10;
count++;
}
Printf (" digit % d, the sum of the number of you is % d, \ n ", count, sum);
}

What is % l64d operation

Now do not have what problem

CodePudding user response:

Crossing the line, beyond the long int said the scope of the,

Suggest using string is more appropriate,

 # include & lt; stdio.h> 
#include
#include

Int main (void)
{
Char STR [32].
Int ret, len, sum=0, I;

Printf (" please enter a number: ");
Ret=the scanf (" % s ", STR);

While (ret & amp; & STR [0]=='-') {
Printf (" please enter a number greater than 0: ");
Ret=the scanf (" % s ", STR);
}
Do {
Len=strlen (STR);
i=0;
While (STR) [I] {
The sum +=STR [i++] - '0';
}
If (sum==0) {
Printf (" please enter a number greater than 0: ");
Ret=the scanf (" % s ", STR);
}
} while (sum==0);


: printf (" % d, the sum of the number of you is % d \ n ", len, sum);

return 0;
}

For your reference ~


To begin with 0 Numbers, there will be a problem, suggestion perfecting it
  • Related